Updating ALL Triggers with "NOT FOR REPLICATION" in SQL Server 2012 -


we have 505 triggers need not replication flag set. found user query searches '%as%' , adds not replication before that.

the problem hits on 1st instance of as, comment (i.e. -- trigger prevent update of lastupdated column) or trigger name (i.e. trglastupdated).

below have been trying. have suggestions finding correct as , how place not replication before it?

main query:

drop table #triggersnfr create table #triggersnfr (servername varchar(250), dbname varchar(250),tablename varchar(250), triggername varchar(250), fixingscript varchar(max)) exec sp_msforeachdb ' if ''?'' not in (''tempdb'',''master'',''model'',''msdb'') begin use ? insert #triggersnfr select @@servername,''?'' dbname,object_name(parent_object_id) tablename, object_name(o.object_id) [trigger name], stuff (replace(definition,''create trigger'',''alter trigger''), patindex(''%as%'',replace(definition,''create trigger'',''alter trigger'')),0,'' not replication '') + '' go '' ?.sys.objects o join ?.sys.sql_modules m on o.object_id = m.object_id o.type = ''tr'' , objectproperty(o.object_id, ''execistriggernotforrepl'') = 0 , objectproperty(o.object_id, ''ismsshipped'') = 0 end '  select * #triggersnfr order dbname 

which has sample output in fixingscript column:

-- ============================================= -- author:      ##### -- create date: 9/14/2012 -- description: prevents updating of l  not replication astupdated date cause app drop update when next 1 comes along. -- ============================================= alter trigger trgappupdates_upd_lastupdated    on app_register_updates    after update  begin 

have tried changing unsuccessful results:

patindex(''%as%'', 

to

patindex(char(13)+''%as%'' 

or

patindex(''%''+char(13)+''as%'' 

or

patindex(''%''+char(13)+char(10)+''as%'' 

did try ''% as%'' (space before as)?

did try case sensitive search?
patindex(''%as%'', [skipped], collate sql_latin1_general_cp1_cs_as) or other case sesitive collation?

btw, many script :).


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -