在“更新数据”语句的前后,适当增加简单的查询语句,便于查看更新的效果。
下面这句查询的意思是:查看Student表的全部数据。
SELECT * FROM Student
【例3.72】-P115
--第一步:建表
CREATE TABLE Dept_age
(
Sdept CHAR(15), /*系名*/
Avg_age SMALLINT /*学生平均年龄*/
);
--第二步:插入数据
INSERT INTO Dept_age(Sdept,Avg_age)
SELECT Sdept,AVG(Sage)
FROM Student
GROUP BY Sdept;
--第三步:查看数据
SELECT * FROM Dept_age
【例3.73】-P115
SELECT * FROM Student
UPDATE Student
SET Sage=22
WHERE Sno='201215121';
SELECT * FROM Student
【例3.74】-P115
SELECT * FROM Student
UPDATE Student SET Sage= Sage+1;
SELECT * FROM Student
【例3.75】-P116
SELECT * FROM SC
UPDATE SC
SET Grade=1
WHERE Sno IN
(
SELECT Sno
FROM Student
WHERE Sdept= 'CS'
);
SELECT * FROM SC
【例3.80】-P117
SELECT * FROM Student
UPDATE Student
SET Sdept = NULL
WHERE Sno='201215121';
SELECT * FROM Student
来源:CSDN
作者:HBU_David
链接:https://blog.csdn.net/qq_38975453/article/details/104702977