Register   |  Login
You are hereArticles
 Article Details
Insert Values into an Identity Column

Is it possible to insert values into identity column of a table in SQL Server?

Yes it is possible and very simple.

Lets say there is a table Country and which has got ID, Name and Description. ID column is an  Identity column with auto increment set.

We want to import data from other SQL Server database or MS access or MS Excel or any other source. This source database has got already IDs generated. We also want to use the same IDs for some reason. Since the Country table has got ID column as Identity column, it is not possible to import, since import operation will try to insert records.

So we need to run the following query to enable the identity insert before we start import operation.

SET IDENTITY_INSERT Country ON  

You can disable the identity insert after the import operation by using the following query

SET IDENTITY_INSERT Country OFF

I hope this will help the developers who want import the data along with the identity columns.

 

 


Written By: Kumaravel
Date Posted: 1/1/2009
Number of Views: 569


Comments
lu juan Says:
4/5/2011 5:25:05 PM

My favorite part of the suite is Microsoft Office 2010 . You can use it like a fancy clipboard, but Office 2010 is much more powerful and useful.So, I'm forced to pay for an upgrade to Microsoft Office that I did not want.For the price, you can't go wrong with Outlook 2010 Home & Student. And, I may or may not be able to use the Product Key on the package I purchased to activate only Word, Excel, Microsoft outlook 2010PowerPoint and OneNote, the programs I thought I was buying. The only answer was to go to MS Office, or have everyone else in the world switch to Office 2007 .The instructions on the Microsoft website for activating Office imply that the full Microsoft Office 2007 Professional suite is the only version eligible for proper licensing.


You must be logged in to submit a comment.

Return