how to write insert querry for two tables
-
i have to insert into two tables 1st table orders orderno int primary key autoincrement, username nvarchar(50) , shopname nvarchar(50), email nvarchar(100) 2nd table is Orderdetails serialno int primarykey autoincrement, orderno int foreignkey, categorynamee nvarchar(50), itemkey nvarchar(50), itemkeyname nvarchar(50), currentqty decimal, salesprice decimal, quantity int, total decimal can you give example which helps me
-
i have to insert into two tables 1st table orders orderno int primary key autoincrement, username nvarchar(50) , shopname nvarchar(50), email nvarchar(100) 2nd table is Orderdetails serialno int primarykey autoincrement, orderno int foreignkey, categorynamee nvarchar(50), itemkey nvarchar(50), itemkeyname nvarchar(50), currentqty decimal, salesprice decimal, quantity int, total decimal can you give example which helps me
I am assuming you are using SQL 2005 or better. Firstly, you need to insert into the order table and get the order number by using scope_identity. Then use this to insert into the order details. The whole lot needs wrapping in a single transaction (clue - the bold words should be used for searching)
Bob Ashfield Consultants Ltd