On 3?20?, ??5?05?, "S.Scarciglia" <salvatore.scarcig...@opis.it>
wrote:
> Hi all,
> I have a complex trigger that must be applied on almost every table of
> my database. I'd like to create a SP or a FUNCTION with just one
> parameter (the table name) and call it on every table in order to create
> the trigger on the provided table.
>
> Is it possible ? If not, have you an idea to solve my problem ?
>
> Many thanks in advance !
> Regards,
> Salvatore
use dynamic sql like below:
CREATE PROC s_BindTriggerToTable
@tableName VARCHAR(200)
AS
DECLARE @sqlString NVARCAHR(4000)
SELECT @sqlString = ''
SELECT @sqlString = @sqlString + 'CREATE TRIGGER ON TABLE ' +
@tableName + '
.....
--PRINT @sqlString
EXEC sp_executesql @sqlString
go