我有2张桌子,custlogin
and custinfo
:
custlogin
:
custid int primary key auto notnull
custusename varchar(25)
custpassword varchar(50)
custinfo
:
custid foriegnkey custlogin.custid ondelete set NULL
custfirstname varchar(25)
custlastname varchar(25)
custaddress varchar(100)
我想编写一个存储过程,它将插入到两个表中
更准确地说,插入custlogin
with custusername custpassword
,这将返回custid
用作外键custinfo
.
我进行了很多搜索,但没有找到任何解决方案。
它会像下面这样。您可以使用SCOPE_IDENTITY()
获取范围内最后一个自动生成的 ID,在本例中是此存储过程:
create procedure NameOfYourProcedureHere
as
begin
SET NOCOUNT ON;
SET XACT_ABORT ON;
insert into custlogin(custusename, custpassword)
values ('','') -- put values here (from parameters?)
insert into custinfo(custid, custfirstname, custlastname, custaddress)
values (SCOPE_IDENTITY(), '', '', '') -- put other values here (from parameters?)
SET NOCOUNT OFF;
SET XACT_ABORT OFF;
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)