实验一数据库设计实验名称:数据库设计实验内容:以所在学校选课和课程管理为实际应用背景,设计一个教学管理数据库。
假设至少包含以下需求:学生信息管理;课程信息管理;教师信息管理;学生选修课程及成绩信息管理;教师负责课程和讲授课程信息管理。
实验目的:通过实践,掌握本章介绍的数据库设计方法。
学会使用PowerDesigner来完成数据库设计过程。
实验方法(或程序源代码):(1)、根据实验内容明确要完成的系统功能。
(2)、运行PowerDesigner创建概念数据模型转换成逻辑数据模型,建立实体、属性和联系。
对关键字、空值、域完整性等做出必要的描述,根据实际情况确定联系的类型。
(3)、将检查无误的概念数据类型转换成逻辑数据模型,并对生成的逻辑数据模型作必要的修改。
(4)、选择一个实际的DBMS软件根据逻辑数据模型生成物理数据模型,并对生成的物理数据模型作必要的修改。
实验数据、结果分析、总结问题:(1)学生选课系统扥E-R图(2)概念数据模型图如下(3)逻辑数据模型图如下(4)物理数据模型图如下(5)系统生成的代码为:if exists(select 1 from sys.sysforeignkey where role='FK_教授课程_RELATIONS_学生') thenalter table 教授课程delete foreign key FK_教授课程_RELATIONS_学生end if;if exists(select 1 from sys.sysforeignkey where role='FK_教授课程_RELATIONS_教师') thenalter table 教授课程delete foreign key FK_教授课程_RELATIONS_教师end if;if exists(select 1 from sys.sysforeignkey where role='FK_负责课程_RELATIONS_课程') thenalter table 负责课程delete foreign key FK_负责课程_RELATIONS_课程end if;if exists(select 1 from sys.sysforeignkey where role='FK_负责课程_RELATIONS_教师') thenalter table 负责课程delete foreign key FK_负责课程_RELATIONS_教师if exists(select 1 from sys.sysforeignkey where role='FK_选修课程_RELATIONS_学生') thenalter table 选修课程delete foreign key FK_选修课程_RELATIONS_学生end if;if exists(select 1 from sys.sysforeignkey where role='FK_选修课程_RELATIONS_课程') thenalter table 选修课程delete foreign key FK_选修课程_RELATIONS_课程end if;if exists(select 1 from sys.systablewhere table_name='学生'and table_type in ('BASE', 'GBL TEMP')) thendrop table 学生end if;if exists(select 1 from sys.systablewhere table_name='教师'and table_type in ('BASE', 'GBL TEMP')) thendrop table 教师end if;if exists(select 1 from sys.systablewhere table_name='教授课程'and table_type in ('BASE', 'GBL TEMP')) thendrop table 教授课程end if;if exists(select 1 from sys.systablewhere table_name='课程'and table_type in ('BASE', 'GBL TEMP')) thendrop table 课程if exists(select 1 from sys.systablewhere table_name='负责课程'and table_type in ('BASE', 'GBL TEMP')) thendrop table 负责课程end if;if exists(select 1 from sys.systablewhere table_name='选修课程'and table_type in ('BASE', 'GBL TEMP')) thendrop table 选修课程end if;create table 学生(学号 char(8) not null, 院系 smallint null,姓名 char(10) null,性别 char(2) null,生源 char(6) null,状态 char(4) null,constraint PK_学生 primary key (学号));create table 教师(教师编号 char(8) not null, 院系 smallint null,姓名 char(10) null,性别 char(2) null,职称 char(6) null,专业 char(10) null,constraint PK_教师 primary key (教师编号));create table 教授课程(教师编号 char(8) not null, 学号 char(8) not null,constraint PK_教授课程 primary key (教师编号, 学号));create table 课程(课程编号 char(8) not null, 课程名称 char(20) null,责任教师 char(8) null,学时 smallint null,课程性质 char(10) null,constraint PK_课程 primary key (课程编号));create table 负责课程(教师编号 char(8) not null, 课程编号 char(8) not null, constraint PK_负责课程 primary key (教师编号, 课程编号));create table 选修课程(课程编号 char(8) not null, 学号 char(8) not null, 成绩 smallint null,constraint PK_选修课程 primary key (课程编号, 学号));alter table 教授课程add constraint FK_教授课程_RELATIONS_学生 foreign key (学号)references 学生 (学号)on update restricton delete restrict;alter table 教授课程add constraint FK_教授课程_RELATIONS_教师 foreign key (教师编号) references 教师 (教师编号)on update restricton delete restrict;alter table 负责课程add constraint FK_负责课程_RELATIONS_课程 foreign key (课程编号) references 课程 (课程编号)on update restricton delete restrict;alter table 负责课程add constraint FK_负责课程_RELATIONS_教师 foreign key (教师编号) references 教师 (教师编号)on update restricton delete restrict;alter table 选修课程add constraint FK_选修课程_RELATIONS_学生 foreign key (学号)references 学生 (学号)on update restricton delete restrict;alter table 选修课程add constraint FK_选修课程_RELATIONS_课程 foreign key (课程编号) references 课程 (课程编号)on update restricton delete restrict;实验数据、结果分析、总结问题:运用PowerDesigner程序添加实体,并建立实体之间的联系。