2022年成绩管理数据库 .pdf





《2022年成绩管理数据库 .pdf》由会员分享,可在线阅读,更多相关《2022年成绩管理数据库 .pdf(12页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、1.设有一数据库GradeManager(成绩管理) ,包括四个表:学生表(Student ) 、课程表(Course) 、班级表( Class )以及成绩表( Grade) 。四个表的结构如图2-4 所示,数据如图 2-5 所示。用SQL语句创建四个表。Student 学生表属性名数据类型可否为空含义Sno Char(7) 否学号(唯一)Sname VarChar(20) 否学生姓名Ssex Char(2) 否性别Sage Smallint 可年龄Clno Char(5) 否学生所在班级useGradeManagergo createtableStudent ( 学号char( 7)prim
2、arykey , 姓名nchar( 4)notnull, 性别nchar( 1)notnull, 年龄smallint, 班级char ( 5)notnull ) Go Course 课程表属性名数据类型可否为空含义Cno Char(1) 否课程号(唯一)Cname VarChar(20) 否课程名称Credit Smallint 可学分useGradeManagergo createtableCourse ( 课程号char( 1)primarykey , 课程名称varchar( 20 )notnull, 学分smallint ) goClass 班级表属性名数据类型可否为空含义Clno
3、Char(5) 否班级号(唯一)Speciality VarChar(20) 否班级所在专业Inyear Char(4) 否入校年份Number Integer 可班级人数Monitor Char(7) 可班长学号名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 12 页 - - - - - - - - - useGradeManagergo createtableClass ( 班级号char( 5)primarykey , 专业varchar( 20 )notnull,
4、 入学年份char ( 4)notnull, 班级人数integer, 班长学号char ( 7) ) Go Grade 成绩表属性名数据类型可否为空含义Sno Char(7) 否学号Cno Char(1) 否课程号Gmark Decimal(4,1) 可成绩useGradeManagergo createtableGrade ( 学号char( 7)notnull, 课程号char ( 1)notnull, 成绩decimal( 4, 1) ) go图 2-4 成绩管理数据库中的表结构Student 学生表Sno Sname Ssex Sage Clno 2000101 李勇男20 0031
5、1 2000102 刘诗晨女19 00311 2000103 王一鸣男20 00312 2000104 张婷婷女21 00312 2001101 李勇敏女19 01311 2001102 贾向东男22 01311 2001103 陈宝玉男20 01311 2001104 张逸凡男21 01311 Course 课程表Cno Cname Credit 1 数据库4 2 离散数学3 3 管理信息系统2 4 操作系统4 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 12 页
6、- - - - - - - - - 5 数据结构4 6 数据处理2 7 C语言4 Class 班级表Clno Speciality Inyear Number Monitor 00311 计算机软件2000 89 2000101 00312 计算机应用2000 68 2000103 01311 计算机软件2001 98 2001103 Grade 成绩表Sno Cno Gmark 2000101 1 92 2000101 3 88 2000101 5 86 2000102 1 78 2000102 6 55 2000103 3 65 2000103 6 78 2000103 5 66 2000
7、104 1 54 2000104 6 83 2001101 2 70 2001101 4 65 2001102 2 80 2001102 4 90 2001102 6 83 2001103 4 76 2001103 6 56 图 2-5 成绩管理数据库中的数据加入完整性约束说明,如图3-6 所示,请用SQL语句完成图中约束的说明。Student 学生表属性名数据类型可否为空含义完整性约束Sno Char(7) 否学号主码Sname VarChar(20) 否学生姓名Ssex Char(2) 否性别男或女,默认为男Sage Smallint 可年龄大于 14,小于 65 Clno Char(5)
8、 否学生所在班级外部码,级联useGradeManagergo 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 12 页 - - - - - - - - - altertableStudent addconstraintPK_Student primarykey ( 学号 ) go - 添加主键约束altertableStudent addconstraintDF_sexdefault ( 男 )for性别go - 添加默认值,默认性别为男altertableStuden
9、t addconstraintck_xingbiecheck ( 性别 = 男or性别 = 女 ) go - 添加 check约束,指定性别输入为男或女altertablestudent addconstraintck_nianlingcheck ( 年龄 between 14 and 65 ); go - 添加 check约束,指定年龄输入范围是1465 altertableStudent addconstraintFK_class_studentforeignkey ( 班级 ) ReferencesClass( 班级号 ) - 添加外键约束ondeletecascade - 指定为级联删
10、除go Course 课程表属性名数据类型可否为空含义完整性约束Cno Char(1) 否课程号主码Cname VarChar(20) 否课程名称Credit Smallint 可学分1、2、3、4、5、6 之一useGradeManagergo altertableCourse addconstraintPK_Courseprimarykey ( 课程号 ) go - 为课程号添加主键altertableCourse add constraintck_Coursecheck ( 学分 =1or学分 =2or学分 =3or学分 =4or学分 =5or学分 =6) go - 添加 check约束
11、,指定学分只能为1,2,3,4,5,6Class 班级表属性名数据类型可否为空含义完整性约束名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 12 页 - - - - - - - - - Clno Char(5) 否班级号主码Speciality VarChar(20) 否班级所在专业Inyear Char(4) 否入校年份Number Integer 可班级人数大于 1, 小于 100 Monitor Char(7) 可班长学号外部码useGradeManagergo a
12、ltertableclass addconstraintCK_banjirenshucheck ( 班级人数 1 and班级人数 =0 and成绩 = 100 ) go - 添加 check约束,指定成绩范围为0100 图 3-6 加了约束说明后的表结构2.针对以上四个表,用SQL语言完成以下各项操作:给学生表增加一属性Nation (民族),数据类型为Varchar (20) ;useGradeManager go altertablestudent add民族varchar( 20 )null go - 使用 add 可以添加新列删除学生表中新增的属性Nation ;useGradeMan
13、ager go altertablestudent dropcolumn民族go - 使用 drop删除列向成绩表中插入记录(”2001110” , ”3” ,80) ;useGradeManager goinsertintoStudentvalues ( 2001110, 李四 , 男 , 20, 01311) go - 添加该记录是为了能使下一条记录顺利添加,因为grade表的【学号】字段列上含外键约束,该外键参照Student表的主键字段列【学号】, 为了保证数据的完整性,Student表中因含有 2001110记录的一行数据。insertGrade values ( 2001110,
14、3, 80) go - 使用 insert into添加一条记录修改学号为” 2001110”的学生的成绩为70 分;useGradeManager goupdateGradeset成绩 =70 where学号=2001110 go - 使用 update修改一条记录删除学号为” 2001110”的学生的成绩记录;useGradeManagergo 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 12 页 - - - - - - - - - deletefromGrade
15、where学号= 2001110 go - 使用 delete语句删除一条记录3.针对以上四个表,用SQL语言完成以下各项查询:1. 找出所有被学生选修了的课程号;useGradeManagergo selectdistinct课程号fromGradego - 从 grade表中查询出所用被学生选修的课程号(grade表为成绩表, 被选修的课程必须有成绩,所以从该表中查询),distinct关键字用来删除重复行。 2. 找出 01311 班女学生的个人信息;useGradeManager go select* fromStudentwhere班级 =01311 and性别 = 女 go3. 找
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年成绩管理数据库 2022 年成 管理 数据库

限制150内