MySQL TRUNCATE和DROP命令之间的显着区别是什么?
MySQLTRUNCATE和DROP命令之间最显着的区别是TRUNCATE命令不会破坏表的结构,但是相反,DROP命令也会破坏表的结构。
示例
mysql> Create table testing(id int PRIMARY KEY NOT NULL AUTO_INCREMENT,Name Varchar(20));
mysql> Insert into testing(Name) Values('Ram'),('Mohan'),('John');
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)现在,在按如下所示对“测试”表进行TRUNCATING之后,其结构仍保留在数据库中,并且还初始化了PRIMARYKEY。
mysql> Truncate table testing; 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; mysql> DESCRIBE testing; ERROR 1146 (42S02): Table 'query.testing' doesn't exist
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短