1.对于student表,将所有所在系部信息为’CS’的改为’计算机科学系’.
UPDATE student
SET Sdept='计算机科学系'
WHERE Sdept='CS';
2.对于course表,将数据结构课程的学分改为3。
UPDATE Course
SET Ccredit='3'
WHERE Cname='数据结构';
3.对于student表,插入一条新记录,它的具体信息为,学号:201216011、姓名:张三、性别:男、年龄:21,所在系部:数学系。
INSERT
INTO Student(Sno,Sname,Ssex,Sage,Sdept)
VALUES('201216011','张三','男',21,'数学系');
4.对于course表,插入两条记录,记录的值自己给定。
INSERT
INTO Course(Cno,Cname,Cpno,Ccredit)
VALUES('8','英语',NULL,'3');
INSERT
INTO Course(Cno,Cname,Cpno,Ccredit)
VALUES('9','C++语言','6','4');
5.对于SC表,将课程编号为2号的最低分改为在原分数*1.1
UPDATE SC
SET Grade=Grade*1.1
WHERE Cno='2' and
Grade in
(SELECT MIN(Grade)
FROM SC
WHERE Cno='2');
6.对于SC表,将课程名为数据库的最低分改为在原分数*1.1
UPDATE SC
SET Grade=Grade*1.1
WHERE Grade in
(SELECT MIN(Grade)
FROM SC,Course
WHERE Cname='数据库' and
SC.Cno=Course.Cno);
7.建立一个新表SC_T,该表的字段名称,类型与表SC一致
CREATE TABLE SC_T
(Sno CHAR(9),
Cno CHAR(4),
Grade SMALLINT,
PRIMARY KEY (Sno,Cno))
8.在SC_T表中,插入若干选课记录,学号为student表中出现的学号,课程编号为1
INSERT INTO SC_T(Sno,Cno)
SELECT Sno,Cno
FROM SC
WHERE Cno='1' and
Sno IN
(select Sno
from SC
group by Sno);
9.在SC_T表中,插入若干选课记录,学号为student表中出现的学号,课程编号为操作系统课程的编号
INSERT INTO SC_T(Sno,Cno)
SELECT Sno,Cno
FROM SC
WHERE Cno in
(SELECT SC.Cno
FROM SC,Course
WHERE Cname='操作系统' and
SC.Cno=Course.Cno) and
Sno in
(select Sno
From SC
group by Sno);
10.用select语句检查8,9的操作是否正确,如果正确,则删除SC_T表中的所有记录
DELETE FROM SC_T
11.在SC_T表中,插入若干选课记录,学号为student表中出现的学号,课程编号为在课程表中出现的所有课程号。
INSERT INTO SC_T(Sno,Cno)
SELECT Sno,Cno
FROM SC
WHERE Cno in
(select Cno
from SC
group byCno) and
Sno in (select Sno
from SC
group by Sno);
12.用select语句检查11的操作是否正确.
SELECT Sno,Cno
FROM SC
WHERE Cno in
(select Cno
fromSC
groupby Cno) and
Sno in (select Sno
fromSC
groupby Sno);