MySQL truncate table语句的使用
Truncate table语句用来删除/截断表里的所有数据
和delete删除所有表数据在逻辑上含义相同,但性能更快 类似执行了drop table和create 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)
到此这篇关于MySQL truncate table语句的使用的文章就介绍到这了,更多相关MySQL truncate table内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!
相关文章:
1. Mysql入门系列:MYSQL服务器内部安全性-安全数据目录访问2. DB2 V9.5工作负载管理之阈值(THRESHOLD)3. mysql 视图操作和存储过程4. 启动MYSQL出错 Manager of pid-file quit without updating file.5. mysql命令行客户端结果分页浏览6. 如何实现MySQL数据库的备份与恢复7. 学好Oracle的六条总结8. Mysql故障排除:Starting MySQL. ERROR! Manager of pid-file quit without updating file9. Mysql入门系列:对MYSQL查询中有疑问的数据进行编码10. MySQL基础教程10 —— 函数之全文搜索功能

网公网安备