简体   繁体   English

RESEED数据库上的标识列

[英]RESEED identity columns on the database

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? 命令将标识列当前值重置为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? 如果没有,是否有另一种方法可以做到这一点?

The value can be omitted. 该值可以省略。 So if you use 所以,如果你使用

DBCC CHECKIDENT (<table_name>, RESEED);

SQL Server sets the ident value to the correct next number - according to the numbers already in use. SQL Server根据已使用的数字将ident值设置为正确的下一个数字。 This is the only way to reseed identity values I know. 这是我知道的重新定位身份值的唯一方法。

Can I use the DBCC CHECKIDENT command to reset an identity column current value to the original one in SQL Server 2008? 我可以使用DBCC CHECKIDENT命令将标识列当前值重置为SQL Server 2008中的原始值吗?

Yes. 是。

If yes, is this the correct way of doing this operation without having any drawback? 如果是的话,这是正确的做法,没有任何缺点吗?

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. 可能的缺点:您最终可能会获得重复的IDENTITY值 - SQL Server无法保证它不会返回尚未使用的值。

Eg 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. 例如,如果您的IDENTITY当前为100,并且您将其重置为1,则可能迟早会产生一个已经使用的值。

The IDENTITY as implemented in SQL Server doesn't check for existing values or anything - it just produces sequential numbers. SQL Server中实现的IDENTITY不检查现有值或任何内容 - 它只生成序列号。 It's up to you - especially if you did a RESEED on that IDENTITY to make sure the values aren't duplicated. 这是给你-特别是如果你做了RESEEDIDENTITY以确保值不重复。

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. 当且仅当feild是主键并且引用任何其他表中的任何外键时,它具有很大的缺点。 reseeding helps to fetching of records in transaction table having indexes on the field. 重新播种有助于获取具有该字段索引的事务表中的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM