如何一次将数据插入两个表中 [英] How to insert data into two table at a time
本文介绍了如何一次将数据插入两个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有两个表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
这篇关于如何一次将数据插入两个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文