Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Monitoring Changes in Your Database Using DDL Triggers


Monitoring Changes in Your Database Using DDL Triggers

Author
Message
David Dye
David Dye
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 308
Comments posted to this topic are about the item Monitoring Changes in Your Database Using DDL Triggers
geoff_lysaght
geoff_lysaght
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 15
This is exactly why I use this site. Simple clear solutions that genuinely add some value to the products I develop. Although, I had to rename the objects (BlameMeTrigger and BlameMeLog). I think this will convey my intentions clearly enough ;¬).

I look forward to the next installment.
uzi yona
uzi yona
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 13
Hi,

I surly join the post saying that this site is the best!.

Though - i have a question - anyone investigated the DB performance issue? My concern is that if I will use the solution detailed here in a DB that is widely used, the DDL will affect the DB response time.

What do you think?

Uzi
janet macdonald-367964
janet macdonald-367964
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 63
I upgraded my SQL2000 to SQL2005 and all of the triggers were fine after the upgrade. Then my vendor provided an upgrade to the ERP which blew away a couple of the triggers on a custom table I had in the database. This has happened before. I simply re-created the triggers as I had done before when we were on SQL2000. Except now, on SQL2005, the triggers won't work. I am creating them in SSMS, logged on as 'sa'. The error message that the user gets is that she is not able to access the server. I've certainly experienced permission problems when I create SSIS packages. Could this be the same kind of problem? I find it difficult to figure out what is wrong with triggers. Any ideas about what I can do?
SuperDBA-207096
SuperDBA-207096
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1595 Visits: 711
David,
Excellent article - concise and to the point! Well done!

Mark
Adam Bean
Adam Bean
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1589 Visits: 2160
Something to keep in mind ... the connection making a change, has to have access to the audit table. That and unless you want to create an audit table per database, it's usually best to use a central table per server.

Check the attached for a script that will push the trigger to all databases. The trigger is more or less the same, but also catches the application. Change the @LoggingDBName to whatever you use for your central DBA/Logging/Admin database.

As stated though, make sure your logins have write access to the changelog table.

---
SQLSlayer
Making SQL do what we want it to do.
Attachments
2005.DDLChange_trg.txt (60 views, 3.00 KB)
Steven Mann
Steven Mann
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 20
In my environment I have 20 databases that are constantly updated 24 hours a day. The application uses one user account so my question has two parts.

1. Can I exclude this user from the trigger?

2. With changes being made constantly is there a way to keep the table size down?
cliffb
cliffb
Say Hey Kid
Say Hey Kid (709 reputation)Say Hey Kid (709 reputation)Say Hey Kid (709 reputation)Say Hey Kid (709 reputation)Say Hey Kid (709 reputation)Say Hey Kid (709 reputation)Say Hey Kid (709 reputation)Say Hey Kid (709 reputation)

Group: General Forum Members
Points: 709 Visits: 438
Steven Mann (10/2/2008)
In my environment I have 20 databases that are constantly updated 24 hours a day. The application uses one user account so my question has two parts.

1. Can I exclude this user from the trigger?

2. With changes being made constantly is there a way to keep the table size down?


1) In your trigger you can check the login name

SET @loginname = @data.value('(/EVENT_INSTANCE/LoginName)[1]',
'NVARCHAR(100)')
....

IF @loginname != 'appuser'
BEGIN
-- do the work
END



2) You can implement a job that does cleanup on a regular basis.

We just recently implemented this in our three main databases for one of our applications, logging to a central table (yes Adam, user has the rights =) ) just in our dev environment (we have a strict dev->qa->production process so we really just need to identify/validate which objects need to be pushed for a release). We have not had an opportunity to use it just yet, but seems to be working fine with the testing we have done.



Dugi
Dugi
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1486 Visits: 3511
Nice one ... I like it, is very simple!

Wink

============================================================
SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Carla Wilson-484785
Carla Wilson-484785
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1755 Visits: 1949
David,
Thanks for the elegant trigger, perfect for keeping an eye on those rogue developers! (like me -- hey, wait a minute ...) Wink
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search