删除表中的数据:
语法格式:
······delete from 表名 where 条件;
注意:没有where条件会全部删除。
例:删除10部门的数据:
mysql> select * from dept1;
+--------+-------+------+
| DEPTNO | DNAME | LOC |
+--------+-------+------+
| 10 | x | y |
| 20 | x | y |
| 30 | x | y |
| 40 | x | y |
| 10 | x | y |
| 20 | x | y |
| 30 | x | y |
| 40 | x | y |
+--------+-------+------+
8 rows in set (0.00 sec)
mysql> delete from dept1 where deptno = 10;
Query OK, 2 rows affected (0.00 sec)
mysql> select * from dept1;
+--------+-------+------+
| DEPTNO | DNAME | LOC |
+--------+-------+------+
| 20 | x | y |
| 30 | x | y |
| 40 | x | y |
| 20 | x | y |
| 30 | x | y |
| 40 | x | y |
+--------+-------+------+
6 rows in set (0.00 sec)
例:删除表中所有数据:
mysql> delete from dept1;
Query OK, 6 rows affected (0.00 sec)
mysql> select * from dept1;
Empty set (0.00 sec)
怎么删除大表:
truncate table 表名;
truncate和delete的区别:
truncate会把表截断,不可回滚。永久丢失,delete可以回滚,表示表格中的数据删除了,但是表格没删,truncate把表格删了只留了表头。