Mysql应用MySQL清空数据表的方法实例与分析
《Mysql应用MySQL清空数据表的方法实例与分析》要点: MySQL数据库中,如果我们想清空数据表(删除数据表中所有内容)的话,可以通过下面两个语句来实现:MYSQL教程 truncate table table_n; delete from table_n; 实例 我们先通过实例看下通过这两种方式清空数据库的过程和结果MYSQL教程 #delete演示 mysql> create table testforde( -> number int not null auto_increment,-> name varchar(20) not null,-> primary key(number) -> ); Query OK,0 rows affected (0.05 sec) #truncate演示 mysql> create table testfortr( -> number int not null auto_increment,0 rows affected (0.04 sec) 以上是两张同样结构的数据表,下面我们先插入数据,然后再分别用 mysql> insert into testforde(name) values('zhagnsan'),('lisi'),('wanger'),('zhaoliu'),('xiaosan'),('qiqi'),('hanba'); Query OK,7 rows affected (0.04 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> insert into testfortr(name) values('zhagnsan'),7 rows affected (0.00 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> select * from testforde; +--------+----------+ | number | name | +--------+----------+ | 1 | zhagnsan | | 2 | lisi | | 3 | wanger | | 4 | zhaoliu | | 5 | xiaosan | | 6 | qiqi | | 7 | hanba | +--------+----------+ 7 rows in set (0.01 sec) mysql> select * from testfortr; +--------+----------+ | number | name | +--------+----------+ | 1 | zhagnsan | | 2 | lisi | | 3 | wanger | | 4 | zhaoliu | | 5 | xiaosan | | 6 | qiqi | | 7 | hanba | +--------+----------+ 7 rows in set (0.00 sec) mysql> delete from testforde; Query OK,7 rows affected (0.02 sec) mysql> truncate table testfortr; Query OK,0 rows affected (0.02 sec) mysql> insert into testforde(name) values('zhagnsan'),7 rows affected (0.00 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> insert into testfortr(name) values('zhagnsan'),7 rows affected (0.00 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> select * from testforde; +--------+----------+ | number | name | +--------+----------+ | 8 | zhagnsan | | 9 | lisi | | 10 | wanger | | 11 | zhaoliu | | 12 | xiaosan | | 13 | qiqi | | 14 | hanba | +--------+----------+ 7 rows in set (0.00 sec) mysql> select * from testfortr; +--------+----------+ | number | name | +--------+----------+ | 1 | zhagnsan | | 2 | lisi | | 3 | wanger | | 4 | zhaoliu | | 5 | xiaosan | | 6 | qiqi | | 7 | hanba | +--------+----------+ 7 rows in set (0.00 sec) 从上面操作过程和结果不难看出,它们最大的区别就是 那么除了上面能明显看出来的区别之外,他们还存在以下几点区别:MYSQL教程 ??? 1、 ??? 2、在事物处理方面, ??? 3、 ??? 4、 ??? 5、正是由于 ??? 6、 总结MYSQL教程 以上就是MySQL清空数据表的全部内容了,希望这篇文章的内容对大家的学习或者工作能有所赞助,如果有疑问大家可以留言交流.MYSQL教程 欢迎参与《Mysql应用MySQL清空数据表的方法实例与分析》讨论,分享您的想法,编程之家PHP学院为您提供专业教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |