MySQL|MySQL truncate table语句的使用
【MySQL|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)
truncate需要什么权限
truncate的执行是先drop后create的, 所以truncate包含drop和create,是一个复合的动作, 对于create不用赋予, 所以只需要赋予drop权限就可以了
到此这篇关于MySQL truncate table语句的使用的文章就介绍到这了,更多相关MySQL truncate table内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- 基于|基于 antd 风格的 element-table + pagination 的二次封装
- tableView|tableView 头视图下拉放大 重写
- py连接mysql
- 2019-01-18Mysql中主机名的问题
- MySql数据库备份与恢复
- 前端代码|前端代码 返回顶部 backToTop
- mysql|InnoDB数据页结构
- mysql中视图事务索引与权限管理
- MYSQL主从同步的实现
- MySQL数据库的基本操作