create PROCEDURE Pro_test ( @userName NVARCHAR(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
时间: 2024-10-14 08:03:40