Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
Have two tables emp and sal,
write a stored procedure that accepts two values ename and sal,
insert the ename in emp and sal in sal table in one query,
sal contains empid as reference key,
Posted

1 solution

In one statement: No, as far as my knowledge goes on.

In one transaction: Yes

SQL
BEGIN TRANSACTION
   DECLARE @EmpID int;
   INSERT INTO emp (Column1 ...) VALUES (....);
   SELECT @EmpID = scope_identity();
   INSERT INTO sal VALUES (@Sal, @EmpID);
COMMIT


Thank you,
Vamsi
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900