如何一次将数据插入两个表中

问题描述:

有两个表emp和sal,

编写一个存储过程,接受两个值ename和sal,

将emp中的ename和sal表中的sal插入一个查询,

sal包含empid作为参考键,

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,

在一个声明中:不,据我的知识而言。



在一次交易中:是



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

In one transaction: Yes

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





谢谢,

Vamsi



Thank you,
Vamsi