Friday, April 22, 2011

DBCC for identity in sql tables.

Learnt about DBCC command for IDENTITY resets or additions. Putting my simple explanation here:

1) The first one will just check if there should be any corrections to be made for

USE AdventureWorks2008R2;
GO
DBCC CHECKIDENT ("Person.AddressType");
GO

Here is the result :

Checking identity information: current identity value '12', current column value '12'.

DBCC execution completed. If DBCC printed error messages, contact your system administrator.


2) The second one just reports the seed value with no corrections.

USE AdventureWorks2008R2;
GO

DBCC CHECKIDENT ("Person.AddressType", RESEED);
GO

Here is the result :

Checking identity information: current identity value '12', current column value '10'.

DBCC execution completed. If DBCC printed error messages, contact your system administrator.

3) The third one reseeds the table with a new seed value.

USE AdventureWorks2008R2;

GO

DBCC
CHECKIDENT ("Person.AddressType", RESEED, 10);

GO

Here is the result for

Checking identity information: current identity value '10', current column value '10'.

DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Try to insert data for the third one :

INSERT INTO Person.AddressType(Name) VALUES('TEST')

Here is the result  after the Insert

No comments:

Post a Comment