您的位置:首页 > 其它

Slackware中文帮助文档(前言)

2009-05-29 18:13 651 查看
对数据库jwgl,按要求建立以下视图
1、查询班级女学生的学生编号、学生姓名、性别 及学生所属班级名称,并把此查询生成视图。
源代码:use jwgl
go
create view girltab as
select student_id,student_name,sex,class_id from student where sex=0
select * from girltab



2、修改上题所建视图定义,除显示班级女学生编号、学生姓名、性别、及学生所属班级名称外,还要求显示学生年龄。
源代码:alter view girltab as
select student_id,student_name,sex,class_id,age from student where sex=0



3、查询上题生成的视图。
源代码:select * from girltab



4、在生成的视图中插入一名男学生的记录。
源代码:insert into girltab values ('g940302','去翻',1,'g9903',20)
select * from student



5、在视图的定义上加上子句with check option,再通过视图插入一名男学生的记录,能否成功,想想为什么。
(1)、没加 with check option ―可以插入记录成功
源代码:alter view girltab as
select student_id,student_name,sex,class_id,age from student where sex=0
insert into girltab values ('g940303','丁琪',1,'g9903',20)
select * from student



(2)、加了 with check option ―插入记录失败
源代码:alter view girltab as
select student_id,student_name,sex,class_id,age from student where sex=0
with check option
insert into girltab values ('g940304','丁',1,'g9903',20)



不能成功,因为with check option子句会检查修改是否满足视图定义。视图定义的是女同学,插入男生记录不满足女同学条件,所以不能插入成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: