RESEED 数据库上的标识列
我可以使用该
DBCC CHECKIDENT(<table_name>, RESEED, value)
命令将 SQL Server 2008 中的标识列当前值重置为原始值吗?
如果是,这是执行此操作的正确方法吗?没有任何缺点吗? 如果没有,是否有其他方法可以做到这一点?
Can I use the
DBCC CHECKIDENT(<table_name>, RESEED, value)
command to reset an identity column current value to the original one in SQL Server 2008?
If yes, is this the correct way of doing this operation without having any drawback?
If not, is there an alternate way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该值可以省略。
因此,如果您使用
SQL Server,请将 ident 值设置为正确的下一个数字 - 根据已在使用的数字。
据我所知,这是重新播种身份价值观的唯一方法。
The value can be omitted.
So if you use
SQL Server sets the ident value to the correct next number - according to the numbers already in use.
This is the only way to reseed identity values I know.
是的。
这是一种有记录的方法。
可能的缺点:您最终可能会得到重复的 IDENTITY 值 - SQL Server 无法保证它不会返回尚未使用的值。
例如,如果您的 IDENTITY 当前为 100,并且您将其重置为 1,那么它迟早会产生一个已在使用的值。
SQL Server 中实现的
IDENTITY
不会检查现有值或任何内容 - 它只是生成连续的数字。这取决于您 - 特别是如果您对该IDENTITY
执行了RESEED
以确保值不重复。Yes.
This is the one documented way of doing it.
Possible drawbacks: you could end up getting duplicate
IDENTITY
values - there's no guarantee from SQL Server that it wouldn't give back a value that's not already in use.E.g. if your
IDENTITY
currently is 100, and you reset it to 1, chances are sooner or later, it will produce a value that's already in use.The
IDENTITY
as implemented in SQL Server doesn't check for existing values or anything - it just produces sequential numbers. It's up to you - especially if you did aRESEED
on thatIDENTITY
to make sure the values aren't duplicated.当且仅当字段是主键并且引用任何其他表中的任何外键时,它有一个很大的缺点。重新播种有助于获取在字段上有索引的事务表中的记录。
It has a great drawback if and only if the feild is a primary key and reference to any foreign key in any other table. reseeding helps to fetching of records in transaction table having indexes on the field.