Ishan Jain
Ishan Jain

Reputation: 8171

Is it possible to Insert into multiple tables using a single Insert statement?

I have two tables table A and table B.

I insert values in both table like this:

Insert Into A (Col1, Col2) Values ("1" "ABC")
Insert Into B (Col1, Col2) Values ("1" "ABC")

but, I want to perform this operation using single insert statement. I used Microsoft SQL Server Management Studio 2008 R2 for this.

Can anyone please tell me is it possible?

Thanks...!!!

Upvotes: 0

Views: 144

Answers (2)

Nadeem_MK
Nadeem_MK

Reputation: 7699

You can pass the Table name by parameter, if and only if, the column names are identical:

Insert Into @tableName (Col1, Col2) Values ("1" "ABC")

Upvotes: 1

Pradeeshnarayan
Pradeeshnarayan

Reputation: 1235

As far as I know it is not possible with a single query. But you can try with a procedure with two insert statements. Or try an after insert trigger.

Upvotes: 1

Related Questions