Reading Time: < 1 minute

Inserting data from other source to identity column and need to retain the indentity values.

Use below Code

set IDENTITY_INSERT dbo.<tablename> ON

insert Statement ex:

insert into PROD_DISP_CATG_SUBCATG(PROD_DISP_CATG_SUBCATG_ID,DISP_CATG_ID,

DISP_SUBCATG_ID,PROD_ID,CREATE_TMSP,LAST_UPDATE_TMSP,LAST_DB_USER_NM) values(’20008′,’1003′,NULL,’1162′,’2007-03-20 13:41:00.000′,NULL,’dbo’)

set IDENTITY_INSERT dbo.<tableName> OFF

insert statement must specify the columns to insert

Communities Tagged : Technology
Tagged: Identity Column , insert , SQL Server