DML Trigger on system view: sys.triggers ?

Hi, MS SQL Experts,
Is there a way to create DML(UPDATE) trigger on system view: sys.triggers, or is there any other ways to monitor the column(is_disabled) change on this view?
(I am using MS SQL 2005)
Thanks,
-Rick
LVL 1
RHADMINAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:
0
RHADMINAuthor Commented:
DDL trigger(ON DATABASE/SERVER )won't work, it can't either audit system view or audit trigger state(ENABLED//DISABLED); it only works on CREATE_TIGGER, ALTER_TIGGER, DROP_TIGGER events.
0
chapmandewCommented:
If you enable the trigger, the DDL trigger would catch that.  You can't create triggers on system views.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

RHADMINAuthor Commented:
Do you have the TSQL as a working example(on AdventureWorks)? I tried, it didn't work.
0
RHADMINAuthor Commented:
Are there some other ways to audit changes on sys.triggers?
0
chapmandewCommented:
CREATE TRIGGER triggername
ON DATABASE
FOR DDL_DATABASE_LEVEL_EVENTS
AS
BEGIN
      SET NOCOUNT ON

      DECLARE @EventData XML
      SET @EventData = EVENTDATA()

      BEGIN TRY
            INSERT INTO audittable  --you have to create this
            (
                  AuditDate,
                  LoginName,
                  ObjectName,
                  EventType,
                  ServerName,
                  DatabaseName,
                  Command,
                  EventData
            )
            SELECT
                  GETDATE(),
                  t.c.value('(LoginName)[1]','VARCHAR(255)'),
                  t.c.value('(ObjectName)[1]','VARCHAR(255)'),
                  t.c.value('(EventType)[1]','VARCHAR(100)'),
                  t.c.value('(ServerName)[1]','VARCHAR(255)'),
                  t.c.value('(DatabaseName)[1]','VARCHAR(255)'),
                  t.c.value('(TSQLCommand/CommandText)[1]','NVARCHAR(MAX)'),
                  @EventData
            FROM      
                  @EventData.nodes('/EVENT_INSTANCE') t(c)
            WHERE
                  t.c.value('(EventType)[1]','VARCHAR(100)') NOT LIKE '%STATISTICS%'
      END TRY
      BEGIN CATCH
            PRINT 'ERROR'
      END CATCH

END
0
RHADMINAuthor Commented:
I've tested your script, it will not catch command like:
DISABLE TRIGGER tr_abc
ON DATABASE
0
chapmandewCommented:
it is a database trigger, not a server trigger.  a server trigger catches the disabliing of database level triggers.
0
chapmandewCommented:
the trigger i gave you is for catching DML triggers when created or altered on user tables or views.
0
RHADMINAuthor Commented:
I know ALTER TABLE statement can also be used to DISABLE TRIGGER, and this ALTER TABLE statement definitely catchable through DDL tigger, my original question is how to catch statement like:

DISABLE TRIGGER tr_abc
ON tbl_abc | DATABASE | ALL SERVER
0
chapmandewCommented:
You're not understanding me....  ALTER TABLE IS catchable through the DDL trigger I gave above.  The statement

DISABLE TRIGGER tr_abc
ON tbl_abc | DATABASE | ALL SERVER

is NOT the same as a trigger on a table...it isa  trigger on the database...and would be caught by a SERVER level trigger.  
0
RHADMINAuthor Commented:
Please try it out first, see if you can catch the event of statement below:

USE AdventuerWorks
DISABLE TRIGGER trigger_ABC
ON table_ABC

I have tried it, it just did not work with DISABLE TRIGGER statement(or ENABLE TRIGGER), but statements like CREATE TRIGGER, ALTER TRIGGER and DROP TRIGGER are all catched with no problem! I don't know why? it seems MS SQL 2005 is missing these 2 events.
0
chapmandewCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RHADMINAuthor Commented:
Thanks, DISABLE TRIGGER statement turns out NOT CATCHable by any means so far!
0
chapmandewCommented:
yep.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.