I need to list all triggers in SQL Server database with table name and table\'s schema.
I\'m almost there with this:
SELECT trigger_name = name, trig
One difficulty is that the text, or description has line feeds. My clumsy kludge, to get it in something more tabular, is to add an HTML
literal to the SELECT
clause, copy and paste everything to notepad, save with an html extension, open in a browser, then copy and paste to a spreadsheet.
example
SELECT obj.NAME AS TBL,trg.name,sm.definition,'<br>'
FROM SYS.OBJECTS obj
LEFT JOIN (SELECT trg1.object_id,trg1.parent_object_id,trg1.name FROM sys.objects trg1 WHERE trg1.type='tr' AND trg1.name like 'update%') trg
ON obj.object_id=trg.parent_object_id
LEFT JOIN (SELECT sm1.object_id,sm1.definition FROM sys.sql_modules sm1 where sm1.definition like '%suser_sname()%') sm ON trg.object_id=sm.object_id
WHERE obj.type='u'
ORDER BY obj.name;
you may still need to fool around with tabs to get the description into one field, but at least it'll be on one line, which I find very helpful.