
MySQL TRUNCATE和DROP命令之间最重要的区别是TRUNCATE命令不会破坏表的结构,而DROP命令会破坏表的结构。
mysql> Create table testing(id int PRIMARY KEY NOT NULL AUTO_INCREMENT,Name Varchar(20));
Query OK, 0 rows affected (0.24 sec)
mysql> Insert into testing(Name) Values('Ram'),('Mohan'),('John');
Query OK, 3 rows affected (0.12 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> Select * from testing;
+----+-------+
| id | Name |
+----+-------+
| 1 | Ram |
| 2 | Mohan |
| 3 | John |
+----+-------+
3 rows in set (0.00 sec)现在在以下情况下截断“testing”表之后,它的结构仍然保留在数据库中,并且它也初始化了主键。
mysql> Truncate table testing; Query OK, 0 rows affected (0.04 sec) mysql> DESCRIBE testing; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | Name | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+ 2 rows in set (0.21 sec)
但是当我们在表上应用DROP命令时,数据库中的结构也会被删除。
mysql> Drop table testing; Query OK, 0 rows affected (0.08 sec) mysql> DESCRIBE testing; ERROR 1146 (42S02): Table 'query.testing' doesn't exist
以上就是MySQL TRUNCATE和DROP命令之间有什么重要的区别?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号