Nu este OK
"The calling stored procedure or Transact-SQL statement must be rewritten to use the SCOPE_IDENTITY() function which will return the latest identity used within the scope of that user statement, and not the identity within the scope of the nested trigger used by replication."
@@IDENTITY and SCOPE_IDENTITY return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
Pentru a intelege mai bine despre ce este vorba, te rog sa analizezi exemplul de mai jos:
create table dbo.[Tabela cu trigger] (
coloana int identity (1,1)
)
create table dbo.[Trigger-ul face insert] (
coloana int identity (10000,1000)
)
go
create trigger trg_ on dbo.[Tabela cu trigger]
for insert as begin
insert into dbo.[Trigger-ul face insert]default values
end
go
insert into dbo.[Tabela cu trigger] default values
select @@Identity as [@@Identity], scope_identity() as [scope_identity]
PS: Coloana [@@Identity] va avea valoarea 10000 (identity "produs" in trigger) iar celalalta coloana va avea valoarea 1 ("produs" in procedura)
LE: mesajul initial era asa:
Procedura arata cam asa:
CREATE PROCEDURE Indentity1
AS
insert into tabela1 default values
return @@IDENTITY
GO
Credeti ca este ok? Mie imi returneaza exact ce trebuie."
Cătălin D.