1、学生选课系统的数据库设计与实现数据库系统概论实验报告学 号:姓 名:提交日期:2010-12-15成 绩: 【实验名称】学生选课系统的数据库设计与实现【实验内容】1、熟悉数据库设计方法;2、熟悉E-R图到关系模式的转换;3、掌握SQL Server 2005数据库的创建SQL语句,理解数据库文件组、文件逻辑名和物理名称的具体含义;4、掌握SQL Server 2005 中用SQL语句建立数据库表,设置数据库完整性约束;5、掌握用SQL Server 2005 建立表的关系图,清楚的表示各表之间的联系。【实验步骤】一、 数据库的逻辑设计图(一)班级、学生、课程实体类型及联系型的ER图图(二)班级
2、实体的分ER图图(三)课程实体的分ER图图(四)学生实体的ER图将上述的E-R图转换为关系模型,关系的主键用下横线标出。学生(学号,姓名,性别,年龄,班级号)课程(课程号,课程名,课时 ,学分)班级(班级号,班级名,人数,专业)选课(课程号学号,成绩)二、 数据库的物理设计1 建表语句:本数据库共创建了四张表,其建表语句如下 1班级表create table class(classNo int not null primary key,className char(20),sdept char(20),number int)2学生表create table student(studentNo
3、int not null primary key,studentName char(20),sex char(20),age int,classNo int)3.课程表create table course(courseNo int not null primary key,courseName char(20),grade int)4选课表create table choice(studentNo int,courseNo int。result int,primary key(studentNo,courseNo)2说明外码语句alter table choiceadd foreign ke
4、y (studentNo) references student(studentNo), foreign key (courseNo) references course(courseNo)alter table studentadd foreign key (classNo) references class(classNo)3记录插入语句:(1)class表:insert class values (40801,yyy,os,35)insert class values (40802,xx,ad,45)insert class values (40803,rr,cs,36)insert c
5、lass values (40804,yy,os,35)insert class values (40805,ee,ry,78)insert class values (40806,yyy,os,35)insert class values (40807,xg,ad,45)insert class values (40808,ry,cs,36)insert class values (40809,yd,os,65)insert class values (408010,eg,ry,48)(2)student表:insert student values(10001,aa,f,23,40801)
6、insert student values(10002,df,f,23,40802)insert student values(10003,adf,f,22,40802)insert student values(10004,gh,m,23,40803)insert student values(10005,dc,f,24,40804)insert student values(10006,sd,m,23,40802)insert student values(10007,dfc,f,23,40803)insert student values(10008,xc,m,25,40805)inse
7、rt student values(10009,sd,f,23,40806)insert student values(100010,cv,f,27,40806)(3)course表:insert course values(1,operating,48,8)insert course values(2,computer,24,4)insert course values(3,music,56,12)insert course values(4,compile,48,8)insert course values(5,oracle,32,6)insert course values(6,sql,
8、48,8)(4)choice表:insert choice values(10001,1,80)insert choice values(10001,2,85)insert choice values(10002,3,86)insert choice values(10002,5,45)insert choice values(10003,1,80)insert choice values(10004,2,87)insert choice values(10004,6,89)insert choice values(10005,1,90)insert choice values(10005,4
9、,100)insert choice values(10006,1,60)insert choice values(10006,3,49)insert choice values(10007,5,70)insert choice values(10008,1,70)insert choice values(10008,6,78)insert choice values(10009,2,80)insert choice values(100010,3,78)insert choice values(100010,1,80)insert choice values(100010,2,78)inse
10、rt choice values(100010,4,89)insert choice values(100010,5,45)4、查询记录:1.选择输出学号、姓名满足性别为女,年龄小于25select studentNo,studentNamefrom studentwhere sex=fand age50的班级输出其班级号和人数create view Numasselect classNo,numberfrom classwhere number50查询语句select * from Num6.插入数据插入数据:插入student表中一个学生,学生名为newstudent,性别为女,年龄34,
11、班级号为40806insert student values(100011,newstudent,f,24,40806)三、 利用SQL Server 2005的Management Studio来创建表的关系图,创建好的关系图如下所示:四 实验体会通过这次实验,让我对sql server2005的使用更加熟悉了,同时也加深了我对课本上数据库知识的理解,这次实验可以说是我第一次完成的一个整体的数据库实验。此次实验中,我完成了从概念设计到逻辑设计,也就是完成了ER图的设计并完成了向关系模型的转换,完成了数据库的建立、表的建立、视图的创建,最后还完成了表之间的关系图。一个数据库的创建首先要对客户的
12、需求进行充分的分析,找出创建数据库所需的实体和实体间的关系画出E-R 图,确定要创建的表的数量和每张表的属性、主键和外键。在动手实验的过程中我遇到很多困难,比如如何删除表中的数据但不保留到日志文件中,数据的不普遍性所造成的查询等操作的空表等等,但是正是这些问题才让我学到了更多,同时也享受到了解决问题后的喜悦。更重要的是,我对数据库产生了浓厚的兴趣,相信以后会把学到的东西应用到实践中去的。五 附录(SQL语句)-班级表create table class(classNo int not null primary key,className char(20),sdept char(20),numb
13、er int)-学生表create table student(studentNo int not null primary key,studentName char(20),sex char(20),age int,classNo int)create table course(courseNo int not null primary key,courseName char(20),courseTime int,grade int)create table choice(studentNo int,courseNo int,result int,primary key(studentNo,
14、courseNo)alter table choiceadd foreign key (studentNo) references student(studentNo), foreign key (courseNo) references course(courseNo)alter table studentadd foreign key (classNo) references class(classNo)insert class values (40801,yyy,os,35)insert class values (40802,xx,ad,45)insert class values (
15、40803,rr,cs,36)insert class values (40804,yy,os,35)insert class values (40805,ee,ry,78)insert class values (40806,yyy,os,35)insert class values (40807,xg,ad,45)insert class values (40808,ry,cs,36)insert class values (40809,yd,os,65)insert class values (408010,eg,ry,48)select * from studentinsert stu
16、dent values(10001,aa,f,23,40801)insert student values(10002,df,f,23,40802)insert student values(10003,adf,f,22,40802)insert student values(10004,gh,m,23,40803)insert student values(10005,dc,f,24,40804)insert student values(10006,sd,m,23,40802)insert student values(10007,dfc,f,23,40803)insert student
17、 values(10008,xc,m,25,40805)insert student values(10009,sd,f,23,40806)insert student values(100010,cv,f,27,40806)insert course values(1,operating,48,8)insert course values(2,computer,24,4)insert course values(3,music,56,12)insert course values(4,compile,48,8)insert course values(5,oracle,32,6)insert
18、 course values(6,sql,48,8)insert choice values(10001,1,80)insert choice values(10001,2,85)insert choice values(10002,3,86)insert choice values(10002,5,45)insert choice values(10003,1,80)insert choice values(10004,2,87)insert choice values(10004,6,89)insert choice values(10005,1,90)insert choice valu
19、es(10005,4,100)insert choice values(10006,1,60)insert choice values(10006,3,49)insert choice values(10007,5,70)insert choice values(10008,1,70)insert choice values(10008,6,78)insert choice values(10009,2,80)insert choice values(100010,3,78)insert choice values(100010,1,80)insert choice values(100010
20、,2,78)insert choice values(100010,4,89)insert choice values(100010,5,45)select * from studentselect * from choiceselect * from classselect *from courseselect studentNo,studentNamefrom studentwhere sex=fand age50select * from Numselect * from studentinsert student values(100011,newstudent,f,24,40806)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1