1.修改数据 UPDATE
(1)修改一行数据:
例子:把刘伟老师转到信息系
UPDATE T SET Dept=’信息’ WHERE TN =’刘伟’
(2)修改多行
例子:把所有的学生年龄加一岁
UPDATE S SET Age = Age +1
例子:将教师表中所有工资小于或等于1000元的讲师的工资提高20%
UPDATE T SET Sal = 1.2 * Sal WHERE (Prof =’讲师’)AND (Sal <= 1000)
(3)用子查询查询修改哪一行
例子:吧讲授C5的教师的岗位津贴增加100
UPDATE T SET Comm = Comm +100 WHERE TNo IN(SELECT TNo FROM T,TC WHERE T.TNo = TC.TNo AND TC.TNo = ‘C5’)
(4)用子查询提供要修改的值
例子:把所有教师的工资提高到平均工资的1.2倍;
UPDATE T SET Sal = (SELECT 1.2 * AGV(Sal) FROM T)
添加数据
(1)添加一行新纪录;
例子:在s表中增添一行学生记录(学号:S7,姓名:郑东,性别:女,年龄:21,系别:计算机)
INSERT INTO S (SNo,SN,Age,Sex,Dept) VALUE(‘S7’,’郑东’,’女’,’21’,’计算机’)
删除数据
(1)删除一行数据
例子:删除刘老师的记录
DELETE FROM T WHERE TN =’刘伟’
(2)删除多行记录
例子:删除 所有老师的授课记录
DELETE FOM TC
删除以后是一个空表;
(3)利用子查询删除
例子:删除刘老师的授课记录
DELETE FROM TC WHERE (TNo = (SELECT TNo FROM T WHERE TN = ‘刘伟’))