Hi,
I am doing sqlbulkcopy from one table to another table.
There are so many tables to do that.I am copying data with for loop for each tables.
But, i am facing with an issue, whenever i copy data from source table to destination table than identity column value is getting changed.
Suppoose there is value like this in identity column of a source table
301
305
605
but when i copy data than it will imported in destination table like that
1
2
3
1) I have tried,
set identity_insert [tablename] ON
//COPY Data from source to destination
set identity_insert [tablename] OFF

Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 21, 2017, 8:40 AM EDT
While doing a bulk insert you have two options -
1 - use
KeepIdentityand preserve the source'sIdentityvalues.2 - Don't map the
Identityfield. If you don't try to assign a value the target table will assign one automatically.Tapan PatelRank #614 · 3.9K reputationPosted Mar 21, 2017, 5:21 AM EDT
//COPY Data from source to destination
set identity_insert [tablename] OFF