Sql server SQL Server 2012范围\u标识建议
我在SQL Server 2012中创建了一个存储过程,我使用了Sql server SQL Server 2012范围\u标识建议,sql-server,stored-procedures,identity-column,scope-identity,Sql Server,Stored Procedures,Identity Column,Scope Identity,我在SQL Server 2012中创建了一个存储过程,我使用了scope\u identity来获取identity列的值,但就我而言,我不知道这是否正确,请帮助 CREATE PROCEDURE Add_Translation @english nvarchar(70), @kurdish nvarchar(70), @english_category int, @kurdish_category int, @result int out AS BEG
scope\u identity
来获取identity列的值,但就我而言,我不知道这是否正确,请帮助
CREATE PROCEDURE Add_Translation
@english nvarchar(70),
@kurdish nvarchar(70),
@english_category int,
@kurdish_category int,
@result int out
AS
BEGIN
SET NOCOUNT ON;
if @english is not null and @kurdish is not null and @english_category is not null and @kurdish_category is not null
begin
insert into english_table values(@english, @english_category);
declare @identityEnglish int;
set @identityEnglish = SCOPE_IDENTITY();
insert into kurdish_table values(@kurdish, @kurdish_category);
declare @identityKurdish int;
set @identityKurdish = SCOPE_IDENTITY();
insert into transactions values(@identityEnglish, @identityKurdish);
set @result = 1;
end
else
begin
set @result = 0;
end
END
我的问题是变量@identityEnglish
会得到english\u表的最后一个标识值吗
变量@identityKurdish
会得到kurdish表的最后一个标识值吗
谢谢。如果插入成功,则
scope\u identity()
工作正常。您可以对DML操作使用“Output”子句
是的,没错。它不起作用了吗?感谢您的帮助,它起作用了,但被问到了,因为表标识列都以1开头,并以1递增,我认为scope_标识在第一个事务中将保持不变