SQL第四章课后习题答案.docx
《SQL第四章课后习题答案.docx》由会员分享,可在线阅读,更多相关《SQL第四章课后习题答案.docx(23页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、SQL第四章课后习题答案USEstudentGOCREATETABLEstud_info(stud_idCHAR(10)NOTNULL,nameNVARCHAR(4)NOTNULL,birthdayDATETIME,genderNCHAR(1),addressNVARCHAR(20),telcodeCHAR(12),zipcodeCHAR(6),markDECIMAL(3,0)-1、利用资源管理器创立表-2.、删除表和创立表usestudentgodroptablestud_infogousestudentgodroptableclassroom_infogousestudentgodropt
2、abledept_codegousestudentgodroptablelesson_infogousestudentgodroptablespecialty_codegousestudentgodroptablestaffroom_infogousestudentgodroptablestud_gradegousestudentgodroptableteacher_infogousestudentgodroptableteacher_schedulegoUSEstudentGOCREATETABLEstud_info(stud_idCHAR(10)NOTNULL,nameNVARCHAR(4
3、)NOTNULL,birthdayDATETIME,genderNCHAR(1),addressNVARCHAR(20),telcodeCHAR(12),zipcodeCHAR(6),markDECIMAL(3,0)USEstudentGOCREATETABLEteacher_info(teacher_idCHAR(10)NOTNULL,nameNVARCHAR(4)NOTNULL,genderNCHAR(1),ageint,tech_titlenchar(5),telephonevarchar(12),salarydecimal(7),course_idchar(10)usestudentg
4、ocreatetablestud_grade(stud_idchar(10)notnull,namenvarchar(4)notnull,course_idchar(10),gradenumeric(4)usestudentgocreatetablelesson_info(course_idchar(10)notnull,course_namenvarchar(12)notnull,course_typenchar(2)notnull,course_markintnotnull,course_timedecimal(3)usestudentgocreatetableteach_schedule
5、(course_idchar(10)notnull,course_datedatetime,course_weekint,room_idchar(6),deptcodechar(2),teacher_idchar(6)usestudentgocreatetabledept_code(deptcodechar(2)notnull,deptnamenvarchar(10),)usestudentgocreatetablespecialty_code(speccodechar(10)notnull,specnamenvarchar(10)usestudentgocreatetablestaffroo
6、m_info(jysh_idchar(4)notnull,jysh_namenvarchar(10),jysh_typenchar(2),jysh_leadernvarchar(4)usestudentgocreatetableclassroom_info (room_idchar(6)notnull,room_namenvarchar(8),room_typenvarchar(6),room_devicenvarchar(10),room_sizeint)usestudentgocreatetablestud_exam(exam_coursenvarchar(10),exam_typenva
7、rchar(6),exam_quantityint,exam_timedatetime,exam_idchar(10),exam_teachernvarchar(10),exam_classroomnvarchar(8),exam_rulenvarchar(10),exam_jilunvarchar(20)-、分别使用对象资源管理器和T语句修改表构造-(1)、将teacher_info表中的teacher_id列长度从6个字符改变到8个字符altertableteacher_infoaltercolumnteacher_idchar(8)-(2)、在dept_code表中加最后一列dept_m
8、emo,其数据类型为可变长度字符型,30位altertabledept_codeadddept_memonvarchar(30)-(3)、向stud_info表中增加“入学时间列,其数据类型为日期型altertablestud_infoaddschooldatedatetime-假设在创立数据表lesson_info时错将课程学分course_mark设计为char(2),现欲修改为decimal(3,1)altertablelesson_infoaltercolumncourse_markdecimal(3,1)-(4).建立约束-(4)1、为student数据库的stud_info表中的m
9、ark列建立check约束altertablestud_infoaddconstraintch_markcheck(markbetween560and600);-(4).2、使用T-SQL语句创立表stud_info,设置stud_info为primarykey约束usestudentgodroptablestud_infogoUSEstudentGOCREATETABLEstud_info(stud_idCHAR(10)NOTNULLconstraintpk_stud_idprimarykey,nameNVARCHAR(4)NOTNULL,birthdayDATETIME,genderNCH
10、AR(1),addressNVARCHAR(20),telcodeCHAR(12),zipcodeCHAR(6),markDECIMAL(3,0)-(4).3为表stud_info的telcode列建立UNIQUE约束altertablestud_infoaddconstraintun_telephoneunique(telcode)-(4).4为stud_grade表中的stud_id列建立foreignkey约束altertablestud_gradeaddconstraintfk_stud_idforeignkey(stud_info)referencesstud_info(stud_i
11、d)-独立实践:altertablestud_infoadddefault(null)forzipcode-(5).插入数据-(5).1insertintostud_infovalues(0401010811,N张源,12-05-1986,N男,N北京市海淀区,010-*,100080,560)select*fromstud_info-独立实践:USEstudentGOINSERTINTOSTUD_INFO(STUD_ID,NAME,BIRTHDAY,GENDER,ADDRESS,TELCODE,ZIPCODE,MARK)VALUES(0401010811,N张源,12-05-1986,N男,
12、N北京市海淀区,010-*,100080,560);INSERTINTOSTUD_INFO(STUD_ID,NAME,BIRTHDAY,GENDER,ADDRESS,TELCODE,ZIPCODE,MARK)VALUES(0401020201,N赵明,08-06-1986,N男,N上海市浦东区,021-*,202100,560);INSERTINTOSTUD_INFO(STUD_ID,NAME,BIRTHDAY,GENDER,ADDRESS,TELCODE,ZIPCODE,MARK)VALUES(0401030101,N王刚,01-02-1986,N男,N天津市南开区,022-*,300000
13、,560);INSERTINTOSTUD_INFO(STUD_ID,NAME,BIRTHDAY,GENDER,ADDRESS,TELCODE,ZIPCODE,MARK)VALUES(0401050201,N陈红,10-25-1986,N女,N武汉市汉口区,027-*,430000,560);INSERTINTOSTUD_INFO(STUD_ID,NAME,BIRTHDAY,GENDER,ADDRESS,TELCODE,ZIPCODE,MARK)VALUES(0401040112,N孙强,06-07-1986,N男,N重庆市沙坪坝,023-*,400000,560);INSERTINTOSTUD
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SQL 第四 课后 习题 答案
限制150内