数据库设计示例文档(完整)物理数据库设计D2小组网上培训系统物理数据库设计陈俊华、董磊、陈俊娜、董昊、海霞、郭云龙1(针对选定的DBMS,生成基表由于本系统主要架构在windows操作系统之上,加之本小组成员对SQLServer 比较熟悉,且系统有并发操作的要求,因此决定采用SQLServer2000 DBMS系统。
2(选择合适的文件组织(Heap, Hash, ISAM, B+ Tree, Clustered)基于在System’s Specification中对系统性能的要求:1)非峰值时,数据查找、更新、存储的平均时间低于1秒2)在峰值时,数据查找、更新、存储的平均时间低于5秒采用SQL Server 2000默认的文件组织结构3(选择建立适当的索引基于在System’s Specification中对事务处理的分析:1)学生情况检索每天50次2)教师情况检索每天10次3)课程检索每天100次4)常见问题检索每天200次5)资料查询每天200次6)试题检索每天50次7)成绩查询每天50次在SQL Server 2000里,在数据库关系图中为表定义一个主键将自动创建主键索引;由于要频繁查询学生姓名、教师姓名、课程名称、题目、成绩,因此在各表的对应列上创建第二索引。
4(定义全局约束根据需求分析,本网上培训系统不允许同一名学生在一个学期中选课超过6 门以上。
5(定义视图用户视图主要是学生视图和教师视图。
6(定义用户访问控制规则用户在进入系统之前必须提交相应的用户名和口令,系统将根据不同的用户而授予不同的权限。
以下是建表语句:1)学生表create table student(StudentID Int(15) not null identity(1,1), StudentName Varchar(20) not null,StudentPassword Varchar(10) not null,StudentStatus Char(1) not null,StudentSex Char(1) not null,EnrollingDate Datetime not null,E-mail Varchar(30),Constraint pk_student primary key clustered(StudentID) )索引:create index student_StudentName on student(StudentName)2)教师表create table teacher (TeacherID Int(15) not null identity(1,1), TeacherName Varchar(20) not null,TeacherPassword Varchar(10) not null,TeacherState Char(1) not null,TeacherSex Char(1) not null,TelNO Int(12),E-mail Varchar(30),Constraint pk_teacher primary key clustered(TeacherID) )索引:create index teacher_TeacherName on teacher(TeacherName)3)课程表create table course (CourseID Int not null identidy(1,1), CourseName Varchar(100) not null,MajorID Int,CourseType Int,CourseCreated Datetime not null,CourseStart Datetime not null,CourseEnd Datetime not null,CourseTime Int not null,CourseScore Int not null,CourseState Char(1) not null,CourseIntro Text,Constraint pk_course primary key clustered(Course_ID) )索引:create index course_CourseName on course(CourseName)4)课堂表create table Classroom (SerialNo Int not null identity(1,1), ClassBegin Datetime,ClassEnd Datetime,onlineBegin Datetime not null, onlineEnd Datetime,Constraint pk_course primary key clustered(SerialNo) )5)申请课程表create table application (ApplyID Int not null identity(1,1), StudentID Int not null, ApplyDate Int not null, CourseID Datetime not null, ApplyType Char(1) not null, ApplyState Char(1) not null, ApplyContent Varchar(200), Constraint pk_course primary key clustered(ApplyID), Constraint ApplicationCourseTooMuchCHECK(NOT EXISTS(SELECT StudentIDFROM applicationGROUP BY StudentIDHAVING COUNT(*)>6))FOREIGN KEY (StudentID) REFERENCES Student (StudentID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (CourseID) REFERENCES Course (CourseID)ON UPDATE CASCADE ON DELETE NO ACTION )6)课程学生表create table courseStudent (CourseID Int not null, StudentID Int not null, SerialNo Int not null, StudentType Char(1) not null, StudentScore Number(3),StudentGrade Number(3),StudentResult Number(3)Constraint pk_courseStudent primary key clustered(CourseID, StudentID,SerialNo),FOREIGN KEY (CourseID) REFERENCES Course (CourseID)ON UPDATE CASCADE ON DELETE NO ACTION,FOREIGN KEY (StudentID) REFERENCES Student (StudentID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (SerialNo) REFERENCES Classroom (SerialNo)ON UPDATE CASCADE ON DELETE NO ACTION )7)课程教师表create table courseTeacher (CourseID Int not null,TeacherID Int not null,SerialNo Int not null,StartDate Datetime,EndDate Datetime,TeacherState Datetime not null,Constraint pk_courseTeacher primary key clustered (CourseID, TeacherID,SerialNo),FOREIGN KEY (CourseID) REFERENCES Course (CourseID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (TeacherID) REFERENCES Teacher (TeacherID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (SerialNo) REFERENCES Classroom(SerialNo)ON UPDATE CASCADE ON DELETE NO ACTION )8)测试表create table test (TestID Int not null,TestName Varchar(100) not null,CourseID Int not null,TestDate Datetime not null,TestTime Int not null default 0, TestType Int not null,TeacherID Int,TestState Char(1) not null,PaperID Int not null,Constraint pk_test primary key clustered(TestID), FOREIGN KEY (CourseID) REFERENCES Course (CourseID)ON UPDATE CASCADE ON DELETE SET NULL )9)试卷表create table testPaper (PaperID Int not null default0 identity(1,1),TestID Int not null,SubjectID Int not null,ObjectAnwser Varchar(255) not null,SubjectAnswer Text,SubjectScore number(3) not null default 0 Constraint pk_testPaper primary key clustered (PaperID), FOREIGN KEY (TestID) REFERENCES Test (TestID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (SubjectID) REFERENCES Subject (SubjectID)ON UPDATE CASCADE ON DELETE NO ACTION )索引:create index testPaper_SubjectID on testPaper (SubjectID)10)测试学生表create table testStudent (Student_ID Int not null,Paper_ID Int not null,Constraint pk_testStudent primary key clustered (StudentID, PaperID) FOREIGN KEY (StudentID) REFERENCES Student (StudentID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (PaperID) REFERENCES TestPaper (PaperID)ON UPDATE CASCADE ON DELETE NO ACTION, )11)测试结果表create table testResult (TestID Int not null,StudentID Int not null,CourseID Int not null,TestDone Char(1) not null,ObjectScore Number(4) not null,SubjectScore Number(4) not null default 0, TestScore Number(4) not null default 0, TestMemo Char(1) not null,Constraint pk_testResult primary key clustered (TestID, StudentID, CourseID),FOREIGN KEY (TestID) REFERENCES Test (TestID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (StudentID) REFERENCES Student (StudentID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (CourseID) REFERENCES Course (CourseID)ON UPDATE CASCADE ON DELETE NO ACTION, )索引:create index testResult_TestScore on testResult(TestScore)12)题库表create table subject (SubjectID Int not null identity(1,1), SubjectType Char(1) not null, SubjectLever Int not null,SubjectContents Varchar(255) not null,SubjectAnswer Text,ObjectAnwser Varchar(255) not null,Constraint pk_subject primary key clustered (SubjectID) )13)练习表create table exercise (ExerciseID Int not null identity(1,1), StudentID Int not null,SubjectID Int not null,TeacherID Int,HandinTime Datetime not null,JudgeState Char(1) not null,JudgeTime Datetime,Grade Int,StudentAnswer Text not null,Constraint pk_exercise primary key clustered (ExerciseID), FOREIGN KEY (StudentID) REFERENCES Student (StudentID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (SubjectID) REFERENCES Subject (SubjectID)ON UPDATE CASCADE ON DELETE NO ACTION, FOREIGN KEY (TeacherID) REFERENCES Teacher (TeacherID)ON UPDATE CASCADE ON DELETE NO ACTION, )。