预览加载中,请您耐心等待几秒...
1/3
2/3
3/3

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

操作过程:创建数据库university,在该数据库中创建student,course,sc,section四张表,代码为:createtablestudent(snumchar(4)notnullprimarykeycheck(substring(snum,1,1)='s'不能漏掉),snamechar(10),sexchar(2)check(sexin('男','女')),deptchar(20),birthdaydatetime,telephonechar(12)check(isnumeric(left(telephone,3))=1Isnumeric函数返回值为1表示是数字,0表示其它andisnumeric(right(telephone,8))=1))createtablecourse(cnumchar(4)notnullprimarykeycheck(substring(cnum,1,1)='c'),cnamechar(20),creditssmallintcheck(credits>=0andcredits<=8),descrchar(10),deptchar(20),textbookchar(40))createtablesc(snumchar(4)foreignkeyreferencesstudent,secnumchar(5)foreignkeyreferencessection,scoreintcheck(score>=0andscore<=100))createtablesection(secnumchar(5)primarykeycheck(secnumlike'[0-9][0-9][0-9][0-9][0-9]'),cnumchar(4)foreignkeyreferencescourse,pnumchar(6)check(substring(pnum,1,1)='p'))小结:字段级完整性约束时容易把“'”疏漏掉,还有容易把“'”跟VB中要加的“''”混淆,例如:sexchar(2)check(sexin('男','女'))会写成sexchar(2)check(sexin(男,女))或者sexchar(2)check(sexin(''男'',''女''))在创建表sc和表section时,两个表不能一起执行,因为secnum为section表的主键,且为sc表的外键。所以建立表的时候要先执行section表,再执行sc表。在创建的四张表中输入数据,代码和视图分别为:Student表:insertintostudentvalues('s001','赵剑','男','计算机','1987-3-25','010-11111111')insertintostudentvalues('s002','王谦','男','交通工程','1986-1-1','027-55555555')insertintostudentvalues('s003','孙启明','男','土木工程','1987-4-1','021-44444444')insertintostudentvalues('s004','宇帆','男','机械工程','1987-7-17','021-33333333')insertintostudentvalues('s005','李晓静','女','生物工程','1988-6-21','030-22222222')insertintostudentvalues('s006','金之林','女','计算机','1988-9-11','040-66666666')insertintostudentvalues('s007','张东晓','男','城市规划','1987-8-2','050-77777777')insertintostudentvalues('s008','海琳','女','城市规划','1988-5-23','070-88888888')Student表2)course表:insertintocoursevalues('c116','大学英语','6','必修课','外语系','《大学英语》,同济大学出版社')insertintocoursevalues('c120','高等数学','6','必修课','数学系','《高等数学》,复旦大学出版社')insertintocoursevalues('c126','大学物理','3','必修课','物理系','《大学物理》,高等教育出版社')insertintocoursevalues('c130','数据库技术','3','限选课','计算机系',