Click here to Skip to main content
14,976,129 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,


insert data into two tables in a single query in sql server


thanks
Posted

You cannot do this through a single query.
Try using a stored procedure instead.
   
You can't insert records in two tables through a single query, instead you can write a trigger on insert of first table to insert in second table.

hope it helps :)
   
Abhinav is correct, you probably do need a stored procedure - the alternative is to use a Transaction[^], where the data is not entered fully in either table until the transaction is complete, and can be rolled back if there is a problem. This would leave your database integrity ok.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900