sql server 2008 r2 - Restoring sql table including identity column -


we had few tables have data deleted.

now have copy database running able restore lost data. running in same server instance.

however, id columns out of sync. rows have been deleted on time etc , example row 98 in new table data 98. maybe 101 in old table.

is possible copy data table across including id? or can turn identity off column. inert data , turn on.

i have tried following code;

truncate table dev_db.dbo.usernames  go  set identity_insert dev_db.dbo.usernames on      insert dev_db.dbo.usernames     select * live_db.dbo.usernames  set identity_insert dev_db.dbo.usernames off 

however error

msg 8101, level 16, state 1, line 6 

an explicit value identity column in table 'dev_db.dbo.usernames' can specified when column list used , identity_insert on.

what avoid in new table copying not make id auto increment copy data on via loop , id stay same

create separate table 1 column (not auto inc) , put last record number in there

then when adding new records create script last number , increase 1 , use number new record.

never have issue of losing id number then.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -