glgcag1991
Programmer
I'm using code I got at a conference to generate a table to log all DDL events in my databases, then I have code to create a trigger on all my databases to add a record to the table upon any DDL event. Being the newbie that I am, I ran the trigger and it created in the first database on my server but none of the others. I'm assuming I need to loop through each database and add the trigger, but first, why does this code add it only to the first database in my server database list?
I'm assuming it's the ON DATABASE part that is adding it to the first db in my list, but what exactly does ON DATABASE mean? If I knew the name of the db, wouldn't I just put ON [dbname], or at least a variable passed in if I didn't know it? (This is the newbie part of the question.)
Second, can I use sp_msforeachdb to cycle through the databases and fire off the create trigger? I'm not sure how to pass the create trigger code into the sp_msforeachdb proc- any suggestions?
I appreciate the help!
Code:
CREATE TRIGGER [trgLogDDLEvent] ON DATABASE
FOR DDL_DATABASE_LEVEL_EVENTS
AS
Second, can I use sp_msforeachdb to cycle through the databases and fire off the create trigger? I'm not sure how to pass the create trigger code into the sp_msforeachdb proc- any suggestions?
I appreciate the help!