1感谢在先。
前两天求助的问题没有想到在几秒钟之内搞定了。
得感谢纸马老师,至少我知道语句没有错误。然后我一直在盘算在哪个地方出错了,隐约中感觉自己应该能解决这个问题。然后灵机一动,豁然开朗,原来我开始执行的时候是以USER身份来做的,现在以administrator一下子就通过了,终于知道原因了,很感谢加我QQ和MSN的朋友,至少我得到了鼓励,感觉很温暖。
2再次向大家讨教关于SQL查询语句方面的东西。
我在教学数据库中建了如下的三个基本表。
S(S#,sname,age,sex)
sc(s#,c#,grade)
c(c#,cname,teacher)
//s#学号,sname学生姓名,age年龄,sex性别,c#课程号,cname课程名称,grade成绩,teacher任课教师。//
create table s
(s# char(6) not null,
sname char(8) not null,
age char(2),
sex char(1),
primary key(s#));
create table c
(c# char(4),
cname char(10) not null,
teacher char(8),
primary key(c#));
create table sc
(s# char(6),
c# char(4),
grade smallint,
primary key(s#,c#),
foreign key(s#)references s(s#),
foreign key(s#)references c(c#),
check(age between 0 and 100));
现在要进行的查询是:
检索全部课程的学生姓名。
已经知道可以这样来写:
select sname
from s
where not exists
(select *
from c
where not exists
(select*
from sc
where sc.s#=s.s#
and sc.c#=c.c#);
这种写法是按照“在表S中找学生,在C中不存在一门课程,这个学生没有学。”的语意来写的,我觉得恁拗口,不知各位大侠有没有更好的写法。如果有,请不吝赐教,本人万分感激!