亲宝软件园·资讯

展开

MySQL truncate table MySQL truncate table语句的使用

丁海龙 人气:0
想了解MySQL truncate table语句的使用的相关内容吗,丁海龙在本文为您仔细讲解MySQL truncate table的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:MySQL,truncate,table,下面大家一起来学习吧。

Truncate table语句用来删除/截断表里的所有数据

mysql> select * from students_bak;
+-----+----------+--------+---------+
| sid | sname  | gender | dept_id |
+-----+----------+--------+---------+
| 101 | zhangsan | male  |   10 |
|  1 | aa    | 1   |    1 |
+-----+----------+--------+---------+
2 rows in set (0.00 sec)

mysql> truncate table students_bak;
Query OK, 0 rows affected (0.16 sec)

mysql> select * from students_bak;
Empty set (0.00 sec)

mysql> set autocommit=off;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from students3;
+-----+-------+--------+---------+--------+
| sid | sname | gender | dept_id | sname2 |
+-----+-------+--------+---------+--------+
| 100 | NULL | 1   |    1 | NULL  |
+-----+-------+--------+---------+--------+
1 row in set (0.01 sec)

mysql> truncate table students3;
Query OK, 0 rows affected (0.06 sec)

mysql> rollback;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from students3;
Empty set (0.00 sec)

mysql> delete from students;
Query OK, 5 rows affected (0.00 sec)

mysql> select * from students;
Empty set (0.00 sec)

mysql> rollback;
Query OK, 0 rows affected (0.07 sec)

mysql> select * from students;
+-----+-------+--------+---------+
| sid | sname | gender | dept_id |
+-----+-------+--------+---------+
|  1 | aa  | 3   |    1 |
|  4 | cc  | 3   |    1 |
|  5 | dd  | 1   |    2 |
|  6 | aac  | 1   |    1 |
| 10 | a   | 1   |    1 |
+-----+-------+--------+---------+
5 rows in set (0.00 sec)

加载全部内容

相关教程
猜你喜欢
用户评论