SQL修改自动增长列ID号从1开始

方法一: 删除原来的字段重新添加

Alter table talbeName Drop Column  ColumnName
Alter table talbeName Add ColumnName Int IDENTITY(1,1)

方法二: 使用命令进行修改

dbcc checkident('test',reseed,0)

检查自动增加ID:  dbcc checkident (表名TableName)

建表事例

create table tb(id int identity ( 1 , 1 ),name varchar ( 10 ))
insert into tb(name) select ' abc '
insert into tb(name) select ' sfd '
insert into tb(name) select ' efawe '
insert into tb(name) select ' asdf2 '
insert into tb(name) select ' efw '
insert into tb(name) select ' afsd '
insert into tb(name) select ' asdf2 '
insert into tb(name) select ' 2fsf '
insert into tb(name) select ' cawe '
insert into tb(name) select ' sdf2qe '

go
select * from tb

来源1:http://soft-development.iteye.com/blog/792088

来源2:https://blog.csdn.net/yanwu616/article/details/2874345?utm_source=blogxgwz8

猜你喜欢

转载自blog.csdn.net/wohingradio88/article/details/83578390