[Oracle 学习笔记] 06 DML
DML包括 INSERT DELETE UPDATE
SQL> INSERT INTO students VALUES(10138,10101, '王一',‘20-12 月-1989’)
SQL> UPDATE students SET student_id = 10195 WHERE student_id = 15252;
SQL> DELETE FROM students_grade;
删除数据 TRUNCATE TABLE 截断表 用于删除表中所有的数据
SQL> TRUNCATE TABLE teachers
DELETE删除的表中所有数据时,不会释放表所占的空间,并且操作可以撤销(ROLLBACK);TRUNCATE TABLE删除表的所有数据时,执行速度更快,而且还会释放表、段所占用的空间,并且操作不能撤销。
带子查询的DML
SQL> INSERT INTO students_computer (SELECT * FROM students WHERE specialty = '计算机');
SQL> UPDATE teachers SET bonus = (SELECT AVG(bonus) FROM teachers) WHERE bonus IS NULL;
SQL> DELETE FROM teachers WHERE wage > (SELECT 1.1*AVG(wage) FROM teachers);