Jump to content

Inserting data into multiple table


houssam_ballout
 Share

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...
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...