Checks the current identity value for the specified table and, if needed, corrects the identity value.
DBCC CHECKIDENT
( 'table_name' [, { NORESEED | {RESEED [, new_reseed_value]} }]
)
If necessary, DBCC CHECKIDENT corrects the current identity value for a column. The current identity value is not corrected, however, if the identity column was created with the NOT FOR REPLICATION clause (in either the CREATE TABLE or ALTER TABLE statement).
Invalid identity information can cause message 2627 when a primary key or unique key constraint exists on the identity column.
The specific corrections made to the current identity value depend on the parameter specifications.
DBCC CHECKIDENT statement | Identity correction(s) made |
---|---|
DBCC CHECKIDENT ('table_name', NORESEED) | The current identity value is not reset. DBCC CHECKIDENT returns a report indicating the current identity value and what it should be. |
DBCC CHECKIDENT ('table_name') or DBCC CHECKIDENT ('table_name', RESEED) |
If the current identity value for a table is lower than the maximum identity value stored in the column, it is reset using the maximum value in the identity column. |
DBCC CHECKIDENT ('table_name', RESEED, new_reseed_value) | The current identity value is set to the new_reseed_value. Use care with this method because it forces the current identity value to be whatever is specified for new_reseed_value. If the value of new_reseed_value is less than the maximum value in the column, error 2627 is generated on subsequent references to the table. |
The current identity value can be larger than the maximum value in the table. DBCC CHECKIDENT does not reset the current identity value automatically in this case. To reset the current identity value when it is larger than the maximum value in the column, use either of two methods:
Whether or not any of the options are specified (for a table containing an identity column; this example uses the jobs table of the pubs database), DBCC CHECKIDENT returns this result set (values may vary):
Checking identity information: current identity value '14', current column value '14'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC CHECKIDENT permissions default to members of the sysadmin fixed server role or the db_owner fixed database role, and are not transferable.
This example resets the current identity value, if needed, of the jobs table.
USE pubs
GO
DBCC CHECKIDENT (jobs)
GO
This example reports the current identity value in the jobs table, and does not correct the identity value, if incorrect.
USE pubs
GO
DBCC CHECKIDENT (jobs, NORESEED)
GO
This example forces the current identity value in the jobs table to a value of 30.
USE pubs
GO
DBCC CHECKIDENT (jobs, RESEED, 30)
GO
ALTER TABLE | USE |
CREATE TABLE | DBCC |
IDENTITY (Property) |