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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT into multpile tables 2

Status
Not open for further replies.

levi71

Programmer
Jul 1, 2001
5
US
How do I automatically insert a value into multiple tables from a web based application using MS SQL 7 or MS SQL 2000.
 
A couple of ways come to mind. You can send multiple insert statements in one SQL script or batch from your WEB APP.

Insert table1 (col1, col2, col3, col4)
Values (val1, val2, val3, val4)
Insert table2 (col1, col2) Values (val1, val2)
Insert table3 (col3, col4) Values (val3, val4)

Or you can create a trigger on a table that would do the inserts in the other table(s) when a new record is inserted.

Create Trigger trgInsert On Table1 For Insert As

Set Nocount On
Insert table2 Select col1, col2 From Inserted
Insert table3 Select col3, col4 From Inserted Terry

"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top