我創建了SQL Server 2012的一個存儲過程,我已經使用scope_identity
獲取身份列的值,但對我來說,我不知道這是正確的或不請幫助SQL Server 2012中SCOPE_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_table
最後一個標識值和變量@identityKurdish
獲得最後一個標識值的kurdish_table
謝謝你..
是的,它看起來對我來說是正確的。 –
是的,這是正確的。它不工作? –
感謝您幫助它正在工作,但問了因爲表標識列從1開始,並增加1,我認爲scope_identity將保持相同的第一個交易 – danarj