Jump to content

Inserting data into multiple table


houssam_ballout

Recommended Posts

Hello all,I'd a web form, and this form must enter data to multiple tables lets say now: 2 tables, (Voucher and Customer)CustomerID is a forgein key in Voucher Table, and Voucher Table has a voucherId in it, how can I insert both CustomerID and its information to the Customer Table and also insert the CustomerID to the Voucher table?Thanks in advance

Link to comment
Share on other sites

  • 2 weeks later...

Hi... First insert record in Customer table, and then use last inserted id like in php:mysql_insert_id.. after insert it to voucher table..Regards,Vijay

Link to comment
Share on other sites

Hello all,I'd a web form, and this form must enter data to multiple tables lets say now: 2 tables, (Voucher and Customer)CustomerID is a forgein key in Voucher Table, and Voucher Table has a voucherId in it, how can I insert both CustomerID and its information to the Customer Table and also insert the CustomerID to the Voucher table?Thanks in advance
declare @lastID intINSERT INTO Customer (columns) VALUES (values);set @lastID = scope_identity()INSERT INTO Voucher(CustomerID) VALUES (@lastID);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...