数据库实验报告Word文档下载推荐.docx
- 文档编号:1040994
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:13
- 大小:309.45KB
数据库实验报告Word文档下载推荐.docx
《数据库实验报告Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《数据库实验报告Word文档下载推荐.docx(13页珍藏版)》请在冰点文库上搜索。
要求:
建一个数据库,包含3~5张表,保留sql语言脚本。
1.建表:
createtableStudent
(Snochar(9)primarykey,
Snamechar(20)unique,
Ssexchar
(2),
Sagesmallint,
Sdeptchar(20)
);
createtableCourse
(Cnochar(4)primarykey,
Cnamechar(40),
Cpnochar(4),
Ccreditsmallint,
foreignkey(Cpno)referencesCourse(Cno)
createtableSC
(Snochar(9),
Cnochar(4),
Gradesmallint,
primarykey(Sno,Cno),
foreignkey(Sno)referencesStudent(Sno),
foreignkey(Cno)referencesCourse(Cno)
2.显示及修改表的结构
sp_helpstudent
altertableCourse
addTeacherchar(6)
3.插入数据
insertStudent
values('
15124'
'
李明'
男'
21,'
MA'
)
4.数据查询
selectSname,2010-Sage
fromStudent;
selectSname,'
YearofBirth:
'
2010-Sage,lower(Sdept)
selectSnameNAME,'
YearofBrith:
Birth,2010-SageBirthday,
lower(Sdept)Department
selectdistinctSno
fromSC;
selectSname
fromStudent
whereSdept='
CS'
;
selectSname,Sage
whereSage<
20;
fromSC
whereGrade<
60;
selectSname,Sdept,Sage
whereSagebetween20and23;
whereSdeptin('
whereSnamelike'
刘%'
whereSnamenotlike'
selectSno,Grade
whereCno='
3'
orderbyGradedesc;
selectcount(*)
selectavg(Grade)
1'
selectCno,count(Sno)
groupbyCno;
selectStudent.*,SC.*
fromStudent,SC
whereStudent.Sno=SC.Sno;
selectfirst.Cno,second.Cpno
fromCoursefirst,Coursesecond
wherefirst.Cpno=second.Cno;
SELECTAVG(Sage)
FROMStudent
whereSnoin
(selectSno
whereCnoin
(selectCno
fromCourse
whereCname='
数据库'
))
selectCno,Cname
whereCnonotin
whereSname='
李勇'
andStudent.Sno=SC.Sno)
selectSno,Sname
wherenotexists
(select*
whereSC.Sno=Student.SnoandSC.Cno=Course.Cno))
selectStudent.Sno,Sname,Ssex,Sage,Sdept,Cno,Grade
fromStudentleftouterjoinSCon(Student.Sno=SC.Sno)
selectStudent.Sno,Sname
whereStudent.Sno=SC.Snoand
SC.Cno='
andSC.Grade>
80
any(
selectSage
andSdept<
>
selectSno
union
2'
createtableDept_age
(Sdeptchar(15),
Avg_ageSMALLINT);
insertintoDept_age(Sdept,Avg_age)
selectSdept,AVG(Sage)
groupbySdept;
updateSC
setGrade=Grade+5
where'
=
(selectSdept
whereStudent.Sno=SC.Sno)
createviewCS_Student
as
selectSno,Sname,Sage
withcheckoption
altertableSC
addconstraintcheckGradecheck(Grade>
0andGrade<
100)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 实验 报告