sqlserver中取出刚插入的主键(主键是guid类型)
时间:2021-07-01 10:21:17
帮助过:1人阅读
25)
)
AS
--
select *
from [dbo].[Table_2]
-- SELECT *
FROM [dbo].[Student]
BEGIN
BEGIN TRAN
DECLARE @tempTable TABLE(tempId uniqueidentifier)
DECLARE @tempId uniqueidentifier
INSERT INTO TABLE_2(UserName) OUTPUT Inserted.UserId INTO @tempTable VALUES(@userName) --
向第一张表中插入数据
SELECT @tempId=tempId FROM @tempTable --
赋值给中间变量
INSERT INTO dbo.Student( StuName, StuAge, StuSex,StuCode )VALUES ( ‘zhansan‘,
10,
‘男‘ ,@tempId )--
把中间变量插入到第二张表中
COMMIT TRAN
END
sqlserver中取出刚插入的主键(主键是guid类型)
标签: