Create trigger for a table After Inserted

These sp creates automatically a trigger when invoked by job in SQL Server, these is very usefull and handy.

Create procedure [dbo].[sp_creates_trigger]

declare @text nvarchar (800 ) -- Declares a variable called texto

set @text='CREATE TRIGGER [subset_trig] ON [dbo].[Subtable] AFTER INSERT AS BEGIN SET NOCOUNT ON; declare @tfield as varchar(8) set @tfiled = (select id_num from inserted)
update subtable set ufield = @tifield where customer<>''Web'' and id_num=@tfield
-- set the trigger in table subtable for an action After Inserted that updates the table
exec sp_executesql @texto -- executes sp_exceutesql with the text command

No response to “Create trigger for a table After Inserted”

Post a Comment