![]() |
From It Tech Blogers |
Esta sp cria automaticamente um trigger a correr a partir de um job no SQL Server, dá muito jeito quando necessitamos de alterar a tabela.
Create procedure [dbo].[sp_creates_trigger]
as
begin
declare @texto nvarchar (800 ) -- Declara a variavel texto
set @texto='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
END'
-- set the trigger in table subtable for an action After Inserted that updates the table
exec sp_executesql @texto -- executa sp com a variavel texto
end
Esta funcionalidade é muito boa quando necessitamos de garantir que este trigger está presente.