November 5, 2009 at 5:52 am
Hi All,
I Have 3 Tables where each table needs to get inserted with 100 Records.1st Table primary key is referenced by 2nd and the 3rd Tables as foreign key.
So I can insert one row in the 1st table and get the primary key of the inserted row and insert the second and the third table. I am repeating this process for 100 times .
Is there any better way to do it .
November 5, 2009 at 7:49 am
November 6, 2009 at 1:59 am
Hi
Thats the only way to do it.
But if you are using cursor or looping to insert, consider using the number table or the tally table.
November 6, 2009 at 3:05 am
No cursors needed ;-). Where do your 100 rows and the related data come from?
If you have any surrogate key within your data (e.g. a client side id, a row number, ...) you can use an ORDERed INSERT into your table1. After this you can calculate all generated IDs by SCOPE_IDENTITY() and @@ROWCOUNT.
Those IDs can be used for your other tables.
Greets
Flo
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply