Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use inserted\deleted table in stored procedure?

I creating triggers for several tables. The triggers have same logic. I will want to use a common stored procedure. But I don't know how work with inserted and deleted table.

example:

SET @FiledId = (SELECT FiledId FROM inserted)
begin tran
   update table with (serializable) set DateVersion = GETDATE()
   where FiledId = @FiledId

   if @@rowcount = 0
   begin
      insert table (FiledId) values (@FiledId)
   end
commit tran
like image 275
Mediator Avatar asked Jan 22 '14 08:01

Mediator


1 Answers

You can

select * into #Inserted from inserted
select * into #Deleted from deleted

and then

use these two temp tables in your stored proc

like image 88
v s Avatar answered Sep 20 '22 17:09

v s