Bronco Solutions

Knowledge Management and Collaboration Platform
Welcome to Bronco Solutions Sign in | Join | Help
in Search

Andrew Renner

Inserting Identity Value

Ever have a table where you need to insert a value into an identity field. 

For example - you may have a lookup table with values 2, 3, 4 - I don't know about you but it annoys me to no end when the 1 value is missing.  You could truncate the table and re-insert all the values... but this is assuming there is no foreign keys...

Here is a way you can actually insert the Identity ID value:


[code language="T-SQL"]SET IDENTITY_INSERT membership.maritalstatus ON
INSERT membership.maritalstatus (MaritalStatusID,[Name]) VALUES(2, 'Married')
SET IDENTITY_INSERT membership.maritalstatus OFF
SELECT * FROM membership.maritalstatus[/code]

If you need to check the identity colum

[code language="T-SQL"]DBCC CHECKIDENT('membership.maritalstatus')
[/code]

If you need to reseed the identity column

[code language="T-SQL"]
DBCC CHECKIDENT('membership.maritalstatus', RESEED, 2)
Insert membership.maritalstatus ([name]) Values ('Married')[/code]
Published Sunday, April 30, 2006 7:58 PM by rennera
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit