Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert new records in two tables in single operation? 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi


I would like to insert new records into two tables at the same time, is there anyone
who could show me how to do this?


Cheers

Magnus
 
I can't see how you could insert records into two different tables with the same INSERT statement - the command doesn't allow for this.

You could make it seem like that, though, by either:

1) using a trigger on the first table that makes the insert into the second table; or
2) calling a stored procedure rather than issuing the Insert statement, passing the SP the values to be inserted, and the SP does both inserts. Robert Bradley
teaser.jpg

 
As foxdev says, it is impossible to insert into two tables in one statements. Even if you have a view defined on two tables, any insert statement on this view that references columns from two table will fail.

The reason to this constraint is that, since each TSQL statement is wrapped in its own transaction, the result of such a statement would be unknwon (COMMITED? or ROLLED BACK?)


Mohammad Mehran Nikoo, MCP
mohmehran@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top