《数据库原理及应用实践考试试卷答案》由会员分享,可在线阅读,更多相关《数据库原理及应用实践考试试卷答案(3页珍藏版)》请在金锄头文库上搜索。
1、08413数据库原理及应用校考实践考试试卷答案一、 使用 SQL 语句创建数据库(10 分)Create database studbOn primary( Name=studb_data,Filename=D:projectstudb_data.mdf,Size=10mb,Filegrowth=20%)Log on( Name=studb_log,Filename=D:projectstudb_data.ldf,Size=3mb,Filegrowth=1mb,Maxsize=20mb)二、 使用 SQL 语句创建表(15 分)1、 创建学生信息表 stuinfoUse studbCreate
2、 table stuinfo(Sno char(8) not null primary key,Sname char(8) not null,Ssex char(2) default(男),Sbirthday datetime,Semail varchar(25)2、 创建课程信息表 courseCreate table course(cno char(8) not null primary key,cname char(8) not null,cscore int)3、 创建成绩表 scoreCreate table score(Sid int identity(1,1),Sno char(
3、8) not null,Cno char(8) not null,Score numeric(4,1)三、 使用 SQL 语句创建约束(15 分)1、 alter table stuinfoAdd constraint ck_ssex check(ssex=男 or ssex=女)2、 alter table stuinfoAdd constraint ck_semail check(semail like %)3、 alter table scoreAdd constraint ck_score (score between 0 and 100)4、 alter table scoreAdd
4、 constraint fk_sno foreign key(sno) references stuinfo(sno)5、 alter table scoreAdd constraint fk_cno foreign key(cno) references course(cno)四、 使用 SQL 操纵语句完成如下要求(15 分)(1) 插入数据1、 insert into stuinfo(sno,Sname,Ssex,Sbirthday,Semail)select (2013001,张冰,男,1995-10-01,) unionselect (2013002,王平,女,1996-10-09,
5、) unionselect (2013003,李强,1994-09-10,) 2、insert into course(cno,cname,cscore)select (01001,计算机基础,男 ,3) unionselect (01002,程序设计语言,女,5) unionselect (01003,计算机原理及应用,6) 3、 insert into score(sno,cno, score)select (2013001,01001,88) unionselect (2013002,01002,79) unionselect (2013003,01003,54) unionselect
6、 (2013003,01001,53) unionselect (2013002,01001,98) (2)更新如下信息1、update stuinfo set ssex=男 where sname=王平2、update course set cscore=8 where cno=01003五、 简单数据查询(每题 5 分,共 35 分)1、 select * from stuinfo 2、 select * from stuinfo where sname=李%3、 select sno,score from score where score60 order by score desc4、
7、 select avg(score),max(score) from score where cno=010015、 select sno, score from score where cno=(select cno from score where cname=计算机基础)6、 select sno,sname from stuinfo inner join score on(stuinfo.sno=score.sno)Where score607、 create view s_sc_cAsSelect sno,sname,cname,scoreFrom stuinfo inner join score on(stuinfo.sno=score.sno)Inner join course on(o=o)六、 高级应用(10 分)Declare i intDeclare sum intSet i=1Set sum=0Where(i=10)BeginSet s=s+iSet i=i+1EndPrint sum