if(object_id('dbo.testa') is not null) drop table testa;
go
create table testa(id bigint not null primary key identity(1,1) ,tname nvarchar(max) );
--3 Times
insert into testa(tname) values(N'ddcawsdqwedf'),(N'ddcawsdqwedf'),(N'ddcawsdqwedf');
select max(id) from testa; --9
truncate table testa;
insert into testa(tname) values(N'ddcawsdqwedf'),(N'ddcawsdqwedf'),(N'ddcawsdqwedf');
select max(id) from testa; --3
delete from testa where id<=3;
insert into testa(tname) values(N'ddcawsdqwedf'),(N'ddcawsdqwedf'),(N'ddcawsdqwedf');
select max(id) from testa; --6
--重置identity seed(新加入的值=seed+step)
DBCC CHECKIDENT ('testa', RESEED, 0)
drop table testa;
truncate 和 delete对自增ID的影响
SQL表操作与Identity重置
最新推荐文章于 2024-02-06 21:19:43 发布
本文演示了如何使用SQL语句创建表、插入数据、截断表、删除记录及重置标识种子等常见操作。通过具体实例展示了不同操作对表的影响。
2557

被折叠的 条评论
为什么被折叠?



