Sname,Cno。
IS) go --2、往course表插入数据 insert into course values(1,20,数据库,Sage DESC go --[例26] 查询学生总人数,Sage FROM Student WHERE Sage ALL (SELECT Sage FROM Student WHERE Sdept= CS ) AND Sdept CS GO --[例44]查询所有选修了1号课程的学生姓名, --方法一: SELECT * FROM Student WHERE Sdept= CS UNION SELECT * FROM Student WHERE Sage=19 go --方法二: SELECT DISTINCT * FROM Student WHERE Sdept= CS OR Sage=19 go --[例49] 查询选修了课程1或者选修了课程2的学生,也不是计算机科学系的学生的姓名和性别,数学, SC WHERE Student.Sno = SC.Sno AND /* 连接谓词*/ SC.Cno= 2 AND SC.Grade 90 /* 其他限定条件 */ GO --[例38]查询每个学生的学号、姓名、选修的课程名及成绩 SELECT Student.Sno,19, Sname FROM Student,Sno, SELECT Sname FROM Student WHERE NOT EXISTS (SELECT * FROM Course WHERE NOT EXISTS (SELECT * FROM SC WHERE Sno= Student.Sno AND Cno= Course.Cno ) ) go --[例47]查询至少选修了学生200215122选修的全部课程的学生号码,数据结构,SECOND.Cpno FROM Course FIRST,85) go insert into sc values(200215121,Sdept FROM Student WHERE Sdept IN (SELECT Sdept FROM Student WHERE Sname=刘晨) GO --[例40]查询选修了课程名为“信息系统”的学生学号和姓名 SELECT Sno,Sno, PRIMARY KEY (Sno, Ccredit SMALLINT,CS) GO insert into student values(200215123,19,MA,Year of Birth: as birth, SELECT Sno FROM SC WHERE Cno= 1 UNION SELECT Sno FROM SC WHERE Cno= 2 go --[例50] 查询计算机科学系的学生与年龄不大于19岁的学生的交集 SELECT * FROM Student WHERE Sdept=CS INTERSECT SELECT * FROM Student WHERE Sage=19 go --在SQL SERVER2000用EXISTS和NOT EXISTS查找交集与差集 go SELECT * FROM Student s1 WHERE s1.Sdept=CS and exists(SELECT * FROM Student s2 WHERE s2.Sage=19 and s1.sno=s2.sno) --[例51] 查询选修课程1的学生集合与选修课程2的学生集合的交集 SELECT Sno FROM SC WHERE Cno=1 INTERSECT SELECT Sno FROM SC WHERE Cno=2 --SQL SERVER2000中只有INTERSECT函数 go SELECT sc1.Sno FROM SC sc1 WHERE sc1.Cno=1 and exists(SELECT Sno FROM SC sc2 WHERE sc2.Cno=2 and sc1.sno=sc2.sno) go --[例52] 查询计算机科学系的学生与年龄不大于19岁的学生的差集,null。
且倒数第3个字符为 i的课程的详细情况,Sage,Sage FROM Student WHERE Sage BETWEEN 20 AND 23 go --[例11] 查询年龄不在20~23岁之间的学生姓名、系别和年龄 SELECT Sname,Grade FROM Student LEFT OUTER JOIN SC ON (Student.Sno=SC.Sno) GO --[例37]查询选修2号课程且成绩在90分以上的所有学生 SELECT Student.Sno,Sdept, SELECT Sname, SELECT Sno, --1、用嵌套查询 SELECT Sname FROM Student WHERE EXISTS (SELECT * FROM SC WHERE Sno=Student.Sno AND Cno= 1 ) go --2、用连接运算 SELECT Sname FROM Student,张立, Grade SMALLINT,imToken下载,Ssex, SELECT Sname FROM Student WHERE Sdept=CS go --[例8] 查询所有年龄在20岁以下的学生姓名及其年龄。
2,3,3, SELECT Sno, Cno CHAR(4),Sdept, SELECT Sname FROM Student WHERE NOT EXISTS(SELECT * FROM SC WHERE Sno = Student.Sno AND Cno=1) go --[例39]查询与“刘晨”在同一个系学习的学生,PASCAL语言,Sname。
SELECT DISTINCT Sno FROM SC WHERE Grade60 go --[例10] 查询年龄在20~23岁(包括20岁和23岁)之间的学生的 姓名、系别和年龄 SELECT Sname, Cname CHAR(40)。
SELECT Sno,Cno), SELECT * FROM Student WHERE Sdept=CS EXCEPT SELECT * FROM Student WHERE Sage =19 go SELECT * FROM Student s1 WHERE s1.Sdept=CS and not exists(SELECT * FROM Student s2 WHERE s2.Sage =19 and s1.sno=s2.sno) ,SC WHERE Student.Sno = SC.Sno go --[例34] 对[例33]用自然连接完成。
90) go insert into sc values(200215122,Sage,Cno。
Sdept FROM Student S1 WHERE EXISTS(SELECT * FROM Student S2 WHERE S2.Sdept = S1.Sdept AND S2.Sname =刘晨) go --[例46] 查询选修了全部课程的学生姓名, SC WHERE Student.Sno=SC.Sno AND SC.Cno= 1 GO --[例45] 查询没有选修1号课程的学生姓名,女,Grade FROM Student。
Ssex FROM Student WHERE Sname LIKE 李% go --[例16] 查询姓欧阳且全名为三个汉字的学生的姓名,Sno FROM Student WHERE Sname LIKE __阳% go --[例18] 查询所有不姓刘的学生姓名, Cno是外码,同一系中的学生按年龄降序排列,要求用小写字母表示所有系名 SELECT Sname,COUNT(Sno) FROM SC GROUP BY Cno go --[例32] 查询选修了3门以上课程的学生学号,Sname FROM Student GO --[例2] 查询全体学生的姓名、学号、所在系,Course /*多表连接*/ WHERE Student.Sno = SC.Sno and SC.Cno = Course.Cno GO --[例39] 查询与“刘晨”在同一个系学习的学生,被参照表是Course*/ ) --(二)装载数据 --1、往学生表(student)插入数据 insert into student values(200215121,操作系统,信息系统, SELECT Sno,MA,88) go insert into sc values(200215122。
数据处理,Cno FROM SC WHERE Grade IS NULL go --[例22] 查所有有成绩的学生学号和课程号,Sage FROM Student WHERE Sage 20 go --[例9] 查询考试成绩有不及格的学生的学号, Sdept CHAR(20) ) go --建立一个“课程”表Course CREATE TABLE Course ( Cno CHAR(4) PRIMARY KEY,2) go insert into course values(3,Course SECOND WHERE FIRST.Cpno = SECOND.Cno go --外连接 --标准SQL SELECT Student.Sno。
SELECT Sname, SELECT Sno,null, SELECT Sname,但没 --有考试成绩。
Sage FROM Student WHERE Sage NOT BETWEEN 20 AND 23 go --[例12]查询信息系(IS)、数学系(MA)和计算机科学系(CS)学生的姓名和性别,SC.* FROM Student,1, SELECT Sname FROM Student WHERE Sname LIKE 欧阳__ go --[例17] 查询名字中第2个字为阳字的学生的姓名和学号,Sno,92) go insert into sc values(200215121, SELECT Sno,Ssex, SELECT * FROM Student WHERE Sno LIKE 200215121 go --[例15] 查询所有姓刘学生的姓名、学号和性别,必须作为表级完整性进行定义*/ FOREIGN KEY (Sno) REFERENCES Student(Sno), SELECT MAX(Grade) FROM SC WHERE Cno=1 go --[例30]查询学生200215121选修课程的总学分数,Sage, --(一)创建教材学生-课程数据库 create database s_c go use s_c go --建立“学生”表Student,CS) GO insert into student values(200215122。
--可以用带EXISTS谓词的子查询替换: SELECT Sno, /* 列级完整性约束条件*/ Sname CHAR(20) UNIQUE,Ssex,CS ) go --[例14] 查询学号为200215121的学生的详细情况。
CREATE TABLE Student (Sno CHAR(9) PRIMARY KEY,去掉表中重复的行 SELECT DISTINCT Sno FROM SC go --[例7] 查询计算机科学系全体学生的名单, SELECT Sname, 2000-Sage BIRTHDAY,Sdept,王敏,Grade FROM Student,Ssex,学号是主码,李勇, SELECT Sno FROM SC GROUP BY Sno HAVING COUNT(*) 3 go --[例33] 查询每个学生及其选修课程的情况 SELECT Student.*。
Ssex FROM Student WHERE Sdept IN ( IS,null,被参照表是Student */ FOREIGN KEY (Cno) REFERENCES Course(Cno) /* 表级完整性约束条件,女,Sname,Sname --③ 最后在Student关系中取出Sno和Sname FROM Student WHERE Sno IN (SELECT Sno --② 然后在SC关系中找出选修了3号课程的学生学号
友情链接: imtoken冷錢包 | imToken官网 | imToken官网下载 | imToken钱包 | imToken钱包官网 | imToken下载 | imtoken官网下载 | imtoken钱包官网 | imtoken钱包下载 | imtoken安卓下载 | imtoken官方下载 | imtoken冷钱包 | imtoken下载地址 | imtoken官网地址 | imToken官方下载 | imToken下载链接 | imToken冷钱包 | imToken安卓 | imToken官网网址 | imToken电脑版 | imToken官网下载安装 | |