RESEED 数据库上的标识列

发布于 2024-10-01 14:21:59 字数 191 浏览 0 评论 0原文

我可以使用该

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南烟雨〆相思醉 2024-10-08 14:21:59

该值可以省略。
因此,如果您使用

DBCC CHECKIDENT (<table_name>, RESEED);

SQL Server,请将 ident 值设置为正确的下一个数字 - 根据已在使用的数字。
据我所知,这是重新播种身份价值观的唯一方法。

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.
This is the only way to reseed identity values I know.

随心而道 2024-10-08 14:21:59

我可以使用 DBCC CHECKIDENT 命令将标识列当前值重置为 SQL Server 2008 中的原始值吗?

是的。

如果是,这是执行此操作的正确方法吗?没有任何缺点吗?

这是一种有记录的方法。

可能的缺点:您最终可能会得到重复的 IDENTITY 值 - SQL Server 无法保证它不会返回尚未使用的值。

例如,如果您的 IDENTITY 当前为 100,并且您将其重置为 1,那么它迟早会产生一个已在使用的值。

SQL Server 中实现的 IDENTITY 不会检查现有值或任何内容 - 它只是生成连续的数字。这取决于您 - 特别是如果您对该 IDENTITY 执行了 RESEED 以确保值不重复。

Can I use the DBCC CHECKIDENT command to reset an identity column current value to the original one in 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.

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 a RESEED on that IDENTITY to make sure the values aren't duplicated.

他不在意 2024-10-08 14:21:59

当且仅当字段是主键并且引用任何其他表中的任何外键时,它有一个很大的缺点。重新播种有助于获取在字段上有索引的事务表中的记录。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文