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 |
ocajuno
Starting Member
5 Posts |
Posted - 2008-08-12 : 10:16:34
|
I have a couple related tables with identities for keys. I'd like to copy the parent record and the related child records. Table1 contains Table1ID (identity) and Table2Id (FK to Table2) columns.Table2 contains Table2ID (identity).I'd like to make a copy of the Table1 and Table2 records without using a cursor. Is this possible? How? Also, can a temp table be avoided?Thanks, Randy |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-12 : 13:22:33
|
1.script out both the tables and apply them with new names (Table1New,Tble2New say)2.SET IDENTITY_INSERT ON for Table2New and populate it with data from Table2INSERT INTO Table2NewSELECT * FROM Table23.SET IDENTITY_INSERT Table2New OFF4..SET IDENTITY_INSERT ON for Table1New and populate it with data from Table1INSERT INTO Table1NewSELECT * FROM Table15.SET IDENTITY_INSERT Table1New OFF |
 |
|
|
|
|