Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2010-05-25 : 09:21:38
|
| I want to insert table A to B and keep the same ID.ID column in B is Identity = Yes.Is it possible? |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-05-25 : 09:30:48
|
| Yes you can do it by setting identity insert on for table B.PBUH |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-25 : 09:31:08
|
If the Id not already exists in table b then yes.set identity_insert table_B oninsert table_bselect * from table_Aset identity_insert table_B off No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2010-05-25 : 09:50:30
|
| The question is that column ID in B is already set Identity = yes and for some reason I can not set it off. (There are 10000 records in B already ID from 1 to 10000)In A, ID is starting on 15000 and then 15001...20000.I want to keep B has the same ID as A after inserting. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-25 : 10:03:20
|
set identity_insert table_B onmeans:let me insert values into the column ID and don't auto generate them.set identity_insert table_B offmeans:I'm ready with inserting and the table can switch back to auto generate the ID's.Have you tried my example that I've posted before? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2010-05-25 : 11:12:01
|
| Thank you.I tried it but have to list all columns to make it working. |
 |
|
|
|
|
|