RESEED identity columns on the database
Asked Answered
A

3

8

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?

Asepsis answered 12/11, 2010 at 13:30 Comment(1)
Actually there are three question here. I am sure you can see them... if you need further explanation just askAsepsis
N
8

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.

Necessitate answered 12/11, 2010 at 13:58 Comment(0)
P
10

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.

Phototransistor answered 12/11, 2010 at 14:13 Comment(1)
EG: Setting your identity to start at 2000: DBCC CHECKIDENT (<table_name>, RESEED, 2000)Harlanharland
N
8

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.

Necessitate answered 12/11, 2010 at 13:58 Comment(0)
C
-1

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.

Chaperone answered 16/2, 2011 at 6:54 Comment(1)
answer makes no sense.Preceptory

© 2022 - 2024 — McMap. All rights reserved.