question

Yazle avatar image
Yazle asked

Insert 1000 rows in three tables at the same time

Hi everyone,

I have three tables related to each other, I want to instert 1000 rows in each of them at the same time, and I dont want to write Insert 1000 times, what should I do ?

sql-server-2012sql serverdatabaseinserttable
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Well, that depends. The data you are inserting, is it in an existing table? or flat file? CSV? Do you really mean "exactly at the same time" or can it be done in the same transaction?

0 Likes 0 ·

1 Answer

·
Yazle avatar image
Yazle answered

Hi @JohnM, thank you. The insert would be on an existing table, and by ¨at the same time¨ I mean in the same transaction

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Where is the data that you are inserting coming from? You can do a simple

INSERT dbo.Table1 (id, firstname, lastnam) SELECT id, firstname, lastname from dbo.Table2;

if the data is another table. If you need to randomly generate data, that's a different story

0 Likes 0 ·

Yeah I need to generate the data @JohnM

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.