RSS

Daily Archives: November 21, 2012

How to enable IDENTITY_INSERT for a table

I wonder how many times every one  us might have stumbled to insert values to identity column.Though identity
column serves as healthy mean of maintaining unique identification for a table and more often then not we do use
identity column to be the primary key field but it does come with it’s own baggage of hindrance, ofcourse until
you know how to unload the baggage

One hindrance that identity column serves is that does not allow you to enter your desired value at a particular
place until you play this little trick with it.While the simplest solution that i have used often to get across this situation
is here to unrevealed.

SET IDENTITY_INSERT TableName ON
INSERT IdentityTable(TheIdentity, TheValue)
VALUES (3, ‘here we go’)
SET IDENTITY_INSERT IdentityTable OFF

This is one of those  little trick that every sql programmer would love to be  scrolled in their sleeves

Advertisements
 
Leave a comment

Posted by on November 21, 2012 in Uncategorized

 

Tags: ,

 
%d bloggers like this: