《SQLServer实验指导》课后作业.docx

上传人:b****5 文档编号:28038329 上传时间:2023-07-07 格式:DOCX 页数:55 大小:372.42KB
下载 相关 举报
《SQLServer实验指导》课后作业.docx_第1页
第1页 / 共55页
《SQLServer实验指导》课后作业.docx_第2页
第2页 / 共55页
《SQLServer实验指导》课后作业.docx_第3页
第3页 / 共55页
《SQLServer实验指导》课后作业.docx_第4页
第4页 / 共55页
《SQLServer实验指导》课后作业.docx_第5页
第5页 / 共55页
点击查看更多>>
下载资源
资源描述

《SQLServer实验指导》课后作业.docx

《《SQLServer实验指导》课后作业.docx》由会员分享,可在线阅读,更多相关《《SQLServer实验指导》课后作业.docx(55页珍藏版)》请在冰豆网上搜索。

《SQLServer实验指导》课后作业.docx

《SQLServer实验指导》课后作业

目录

创建数据库jxsk:

-1-

创建jxsk中的表:

-1-

插入jxsk库中各表值:

-1-

创建数据库jiaoxuedb:

-3-

创建jiaoxuedb中的表:

-3-

插入jiaoxuedb库中各表值:

-3-

实验4:

习题-5-

实验5:

习题-7-

实验6:

习题-7-

实验7:

习题-8-

实验8:

习题-12-

实验9:

习题-17-

实验10:

习题-20-

实验11:

习题-23-

实验12:

习题-26-

实验13:

习题-38-

创建数据库jxsk:

createdatabasejxsk

on

(name=jxsk_dat,filename='d:

\jxsk_dat.mdf')

logon

(name=jxsk_log,filename='d:

\jxsk_log.ldf')

go

创建jxsk中的表:

usejxsk

createtables(

snochar

(2)notnull,

snchar(8)notnull,

sexchar

(2)null,

agetinyintnull,

deptchar(10)null)

createtablet(

tnochar

(2)notnull,

tnchar(8)notnull,

sexchar

(2)null,

agetinyintnull,

profchar(10)null,

salsmallintnull,

commsmallintnull,

deptchar(10)null)

createtablec(

cnochar

(2)notnull,

cnchar(10)notnull,

cttinyintnull,

id_tctinyintnull)

createtablesc(

snochar

(2)notnull,

cnochar

(2)notnull,

scoretinyintnull)

createtabletc(

tnochar

(2)notnull,

cnochar

(2)notnull)

插入jxsk库中各表值:

usejxsk

insertintosvalues('s2','钱尔','男',18,'信息')

insertintosvalues('s3','孙姗','女',20,'信息')

insertintosvalues('s4','李思','男',21,'自动化')

insertintosvalues('s5','周武','男',19,'计算机')

insertintosvalues('s6','吴丽','女',20,'自动化')

insertintosvalues('s7','李奇','男',18,'外语')

insertintosvalues('s8','古明','男',null,'计算机')

insertintosvalues('s9','赵亦','女',17,'计算机')

insertintotvalues('t5','张兰','女',39,'副教授',1300,2000,'信息')

insertintotvalues('t4','张雪','女',51,'教授',1600,3000,'自动化')

insertintotvalues('t3','刘伟','男',30,'讲师',900,1200,'计算机')

insertintotvalues('t2','王平','女',28,'讲师',800,1200,'信息')

insertintotvalues('t1','李力','男',47,'教授',1500,3000,'计算机')

insertintocvalues('c1','程序设计',60,1)

insertintocvalues('c2','微机原理',80,2)

insertintocvalues('c3','数字逻辑',60,3)

insertintocvalues('c4','数据结构',80,4)

insertintocvalues('c5','数据库',60,5)

insertintocvalues('c6','编译原理',60,6)

insertintocvalues('c7','操作系统',60,7)

insertintoscvalues('s2','c5',57)

insertintoscvalues('s2','c6',80)

insertintoscvalues('s2','c7',null)

insertintoscvalues('s3','c1',75)

insertintoscvalues('s3','c2',70)

insertintoscvalues('s3','c4',85)

insertintoscvalues('s4','c1',93)

insertintoscvalues('s4','c2',85)

insertintoscvalues('s4','c3',83)

insertintoscvalues('s5','c2',89)

insertintoscvalues('s9','c1',90)

insertintoscvalues('s9','c2',85)

insertintotcvalues('t2','c5')

insertintotcvalues('t3','c1')

insertintotcvalues('t3','c5')

insertintotcvalues('t4','c2')

insertintotcvalues('t4','c3')

insertintotcvalues('t5','c5')

insertintotcvalues('t5','c7')

insertintotcvalues('t1','c1')

insertintotcvalues('t1','c4')

创建数据库jiaoxuedb:

createdatabasejiaoxuedb

on

(name=jiaoxuedb_dat,filename='d:

\jiaoxuedb_dat.mdf')

logon

(name=jiaoxuedb_log,filename='d:

\jiaoxuedb_log.ldf')

go

创建jiaoxuedb中的表:

usejiaoxuedb

createtablestudent(

snochar(10)notnull,

snamechar(10)notnull,

sexchar

(2)null,

agetinyintnull,

deptchar(10)null)

createtableteacher(

tnochar(10)notnull,

tnamechar(10)notnull,

sexchar

(2)null,

agetinyintnull,

profchar(10)null,

salsmallintnull,

commsmallintnull,

deptchar(10)null)

createtablecourse(

cnochar(10)notnull,

cnamechar(10)notnull,

chourtinyintnull,

ccredittinyintnull)

createtablesc(

snochar(10)notnull,

cnochar(10)notnull,

scoretinyintnull)

createtabletc(

tnochar(10)notnull,

cnochar(10)notnull)

插入jiaoxuedb库中各表值:

usejiaoxuedb

/*insertvaluestostudenttable*/

insertintostudentvalues('001101','宋大方','男',19,'计算机')

insertintostudentvalues('002102','李王','男',20,'信息')

insertintostudentvalues('991101','张彬','男',18,'计算机')

insertintostudentvalues('991102','王蕾','女',19,'计算机')

insertintostudentvalues('991103','张建国','男',18,'计算机')

insertintostudentvalues('991104','李平方','男',18,'计算机')

insertintostudentvalues('991201','陈东辉','男',19,'计算机')

insertintostudentvalues('991202','葛鹏','男',21,'计算机')

insertintostudentvalues('991203','潘桃芝','女',19,'计算机')

insertintostudentvalues('991204','姚一峰','男',18,'计算机')

insertintostudentvalues('001102','许辉','女',22,'计算机')

insertintostudentvalues('001201','王一山','男',20,'计算机')

insertintostudentvalues('001202','牛莉','女',19,'计算机')

insertintostudentvalues('002101','李丽丽','女',19,'信息')

/*insertvaluestoteachertable*/

insertintoteachervalues('000006','许红霞','女',39,'讲师',1100,1200,'计算机')

insertintoteachervalues('000007','许永军','男',57,'教授',2000,3000,'计算机')

insertintoteachervalues('000008','李贵青','女',65,'教授',2000,3000,'计算机')

insertintoteachervalues('000009','王一凡','女',43,'讲师',1200,1200,'计算机')

insertintoteachervalues('000010','田峰','男',33,'助教',500,800,'信息')

insertintoteachervalues('000001','李英','女',39,'副教授',1500,2000,'信息')

insertintoteachervalues('000002','张雪','女',51,'教授',1900,3000,'信息')

insertintoteachervalues('000003','张朋','男',30,'讲师',1000,1200,'计算机')

insertintoteachervalues('000004','王平','女',28,'讲师',850,1200,'信息')

insertintoteachervalues('000005','李力','男',47,'教授',1800,3000,'计算机')

/*insertvaluestocoursetable*/

insertintocoursevalues('01001','计算机基础',60,3)

insertintocoursevalues('01002','程序设计',80,5)

insertintocoursevalues('02003','数据结构',60,6)

insertintocoursevalues('02001','数据库',80,6)

insertintocoursevalues('02002','计算机网络',60,6)

insertintocoursevalues('01003','微机原理',60,8)

insertintocoursevalues('02004','操作系统',60,6)

insertintocoursevalues('03001','软件工程',60,3)

insertintocoursevalues('03002','大型数据库',48,2)

insertintocoursevalues('03003','图像处理',48,2)

/*insertvaluestosctable*/

insertintoscvalues('991101','01001',88)

insertintoscvalues('991102','01001',93)

insertintoscvalues('991103','01001',90)

insertintoscvalues('991101','01002',90)

insertintoscvalues('991102','01002',98)

insertintoscvalues('991103','01002',74)

insertintoscvalues('991104','01002',85)

insertintoscvalues('001201','01002',64)

insertintoscvalues('991104','02001',33)

insertintoscvalues('991104','01001',35)

insertintoscvalues('991201','01001',76)

/*insertvaluestotctable*/

insertintotcvalues('000001','02001')

insertintotcvalues('000008','02002')

insertintotcvalues('000003','02001')

insertintotcvalues('000011','02003')

insertintotcvalues('000001','01001')

insertintotcvalues('000002','01002')

insertintotcvalues('000002','01003')

insertintotcvalues('000004','02002')

insertintotcvalues('000005','01001')

insertintotcvalues('000006','01002')

insertintotcvalues('000003','01003')

实验4:

习题

基于jiaoxuedb实验

1、对个表创建实体完整性;

usejiaoxuedb

altertablestudent

addconstraintpk_snoprimarykey(sno)

altertableteacher

addconstraintpk_tnoprimarykey(tno)

altertablecourse

addconstraintpk_cnoprimarykey(cno)

altertablestudent

addconstraintunique_sunique(sno)

altertableteacher

addconstraintunique_tunique(tno)

altertablecourse

addconstraintunique_cunique(cno)

2、创建表之间的参照完整性。

usejiaoxuedb

altertablescwithnocheck

addconstraintfk_s_scforeignkey(sno)referencesstudent(sno)

ondeletecascade

altertablescwithnocheck

addconstraintfk_c_scforeignkey(cno)referencescourse(cno)

ondeletecascade

altertabletcwithnocheck

addconstraintfk_t_tcforeignkey(tno)referencesteacher(tno)

ondeletecascade

altertabletcwithnocheck

addconstraintfk_c_tcforeignkey(cno)referencescourse(cno)

ondeletecascade

3、用不同的方法创建下面约束。

(1)“姓名”字段取唯一值:

usejiaoxuedb

altertablestudent

addconstraintunique_snaunique(sname)

altertableteacher

addconstraintunique_tnaunique(tname)

(2)“性别”字段取值为:

‘男’或‘女’;默认值:

‘男’;

usejiaoxuedb

altertableteacherwithcheck

addconstraintcheck_t_sexcheck(sex='男'orsex='女')

altertableteacher

addconstraintdf_t_sexdefault'男'forsex

altertablestudentwithcheck

addconstraintcheck_s_sexcheck(sex='男'orsex='女')

altertablestudent

addconstraintdf_s_sexdefault'男'forsex

(3)“年龄”和“分数”字段取值限定为:

0~100之间。

usejiaoxuedb

altertablestudentwithcheck

addconstraintcheck_s_agecheck(age>0andage<100)

altertableteacherwithcheck

addconstraintcheck_t_agecheck(age>0andage<100)

 

实验5:

习题

1、对教师表teacher中的教师号tno创建聚族索引,并按降序排列。

usejiaoxuedb

createclusteredindexind_tno

onteacher(tnodesc)

2、对学生选课表sc,先按课号cno升序排列,再按成绩score降序排列。

cno升序:

usejiaoxuedb

createclusteredindexind_sc_cnoonsc(cnoasc)

score降序:

usejiaoxuedb

createclusteredindexind_sc_scoreonsc(scoredesc)

3、对表student中的学号sno创建唯一索引,并按升序排列。

usejiaoxuedb

createuniqueindexind_s_snoonstudent(snoasc)

实验6:

习题

基于jiaoxuedb实验

1、创建成绩视图score_view,包含学号sno,姓名sn,课程名cn,成绩score。

usejiaoxuedb

go

createviewscore_view

asselectstudent.sno,sname,cname,score

fromstudent,course,sc

wherestudent.sno=sc.snoando=o

go

2、创建一个计算机系学生名单视图s_view,包含学号sno,姓名sn,性别sex。

usejiaoxuedb

go

createviews_view

asselectsno,sname,sex

fromstudent

wheredept='计算机'

go

4、通过上面的视图,修改学号为991102,课号为01001的成绩记录。

usejiaoxuedb

updatescore_viewsetscore=100

wheresno='991102'andcname=

(selectcnamefromcoursewherecno='01001')

go

5、创建一个视图,计算机系学生的成绩单score_view_cdept,版含学号sno,姓名sn,课程名cn,成绩score。

usejiaoxuedb

go

createviewscore_view_cdept

asselectstudent.sno,sname,cname,score

fromstudent,course,sc

wherestudent.dept='计算机'

andstudent.sno=sc.sno

ando=o

go

6、给视图s_view增加一个年龄age字段。

usejiaoxuedb

go

alterviews_view

asselectsno,sname,sex,age

fromstudent

wheredept='计算机'

go

7、创建一个教师工资表视图sal_view,版含字段教师名tname,性别sex,职称prof,工资总和salsum,系别dept。

usejiaoxuedb

go

createviewsal_view

asselecttname,sex,prof,sal+commassalsum

fromteacher

go

8、通过视图查询教师“张明”的工资收入。

usejiaoxuedb

selecttname,salsum

fromsal_view

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1