SQL Server ID自增列重新从1开始算起
数据库原有ID字段,是自增列的,后来把数据全删除后,想让ID自增列从1开始算起

方法1:
1.dbcc checkident('test',reseed,0)
2.insert into test values(55)

select * from test

显示结果:

id      msum

1        55

方法2:

SET IDENTITY_INSERT

允许将显式值插入表的标识列中。

语法:
SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON | OFF }
set identity_insert dbo.test on
test是表名
注意:运用set identity_insert dbo.test on后,insert into时,必须要把需要插入记录的字段写上,如:
insert into test(id,msum)values(1,55)
insert into test(id,msum)values(2,55)
下面的语句的写法是错误的:
insert into test values(55)
insert into test values(1,55)


出处:http://blog.csdn.net/neekerss/archive/2009/04/20/4095090.aspx

相关文章:

  • 2021-06-06
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
猜你喜欢
  • 2021-05-25
  • 2021-05-25
  • 2022-02-07
  • 2021-08-19
  • 2021-12-18
相关资源
相似解决方案