SQL Server Insert Into Identity Column

We all know that if you have an identity column and if you try to insert a value in the identity column, you will get an error. Here is how you can avoid the error

First thing to do here is to set Identity to ON on the tblname you want to insert row in.

SET IDENTITY_INSERT tblname ON

INSERT tblname (ID,colname) VALUES(5,'ajas')

SET IDENTITY_INSERT tblname OFF

Do not forget to set IDENTITY_INSERT to off once you are done with inserting the record because you dont want it to be off if you have an application where developers will be working on it.

Hope this Helps.

Comments

Popular posts from this blog

Making text bold in Adobe Acrobat

Java Keytool Export Private Key, PKCS#12 or .p12 export or conversion from java keystore

iphone 4 ipod touch Change Delete Edit Update Delete wifi wireless key wireless password wireless connection