Home > Database > Mysql Tutorial > mysql教程―清空表truncate及delete区别_MySQL

mysql教程―清空表truncate及delete区别_MySQL

WBOY
Release: 2016-06-01 13:45:58
Original
1251 people have browsed it

bitsCN.com

简而言之,用 truncate清空的表id会从新记录  而delete清空的表则不会从新记录 会继续原数据记录,当然这里id为自增长
=============================================================================================
本文演示如何使用truncate命令,以及delete 与truncate的区别
下面看一款删除mysql一个表中所有数据实例。
truncate table mytable;
利用truncate 清空表,表的id从1开始哦。
下面测试实例
create table `user` ( 
`id` int(11) not null auto_increment,
`name` varchar(100) default null,
 primary key (`id`))
 
插入几条数据
insert into user (name) values ('bob');
insert into user (name) values ('mark');
insert into user (name) values ('alex');
insert into user (name) values ('julia');
查看一下看数据
select * from user; the result is:id         name                                                                                                                                                                                                                                    1          bob        2          mark
  3          alex        4          julia
看一下truncate实例
truncate table user;
插入一条数据
insert into user (name) values ('bill');
查看结果
select * from user;
the result is:id         name              1          bill

正如你可以看到旧的记录被删除除,而新的得到的id字段1

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template