求一条语句修改主键Id字段的identity开始值

icbc_ljt 2010-10-29 12:41:28
原来Id开始值为1,我想把以后插入的值都从1000开始,用SQL语句实现,而不是手动改表
...全文
129 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
icbc_ljt 2010-10-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 findcaiyzh 的回复:]
试一试
dbcc checkident (mytable, reseed, 999)

没有验证过。
参考
Tips for SQL Server Identity Columns
[/Quote]


可以用
You can reseed the indentity value, that is, to have the identity values reset or start at a new predefined value by using DBCC CHECKIDENT. For example, if I have a table named MYTABLE and I want to reseed the indentity column to 30 I would execute the following:


dbcc checkident (mytable, reseed, 30)
If you wanted to reseed the table to start with an identity of 1 with the next insert then you would reseed the table's identity to 0. The identity seed is what the value is currently at, meaning that the next value will increment the seed and use that. However, one thing to keep in mind is that if you set the identity seed below values that you currently have in the table, that you will violate the indentity column's uniqueness constraint as soon as the values start to overlap. The identity value will not just “skip” values that already exist in the table.




宝_爸 2010-10-29
  • 打赏
  • 举报
回复
试一试
dbcc checkident (mytable, reseed, 999)

没有验证过。
参考
Tips for SQL Server Identity Columns
HONGGULANZHOU 2010-10-29
  • 打赏
  • 举报
回复
id是主键吗?先删出标识,后更新,最后设标识

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧