Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Ciupaz
Posting Yak Master
232 Posts |
Posted - 2011-08-24 : 08:50:24
|
Hello,how can I write a trigger that save me (in a table, for example) modifications at the table, stored procs and funcionts in my DB?The information I need to save is: user, dateOfModification and (if possible) the modification itself.Is it possible write a trigger like this?I'm using SQL Server 2008.Thanks in advance.Luigi |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-08-24 : 10:15:45
|
You can do this with DDL Triggers |
 |
|
Ciupaz
Posting Yak Master
232 Posts |
Posted - 2011-08-24 : 10:26:51
|
Something like this could be ok? CREATE TRIGGER safety ON DATABASE FOR DROP_TABLE, ALTER_TABLE, ALTER_PROCEDURE, ALTER_FUNCTION, DROP_PROCEDURE,DROP_FUNCTIONAS INSERT dbo.LogTrigger(Description,DateExecute) SELECT EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)'),GETDATE() |
 |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-08-24 : 11:52:50
|
looks good. I'll also capture('(/EVENT_INSTANCE/LoginName)[1]',sysname') |
 |
|
gwilson67
Starting Member
42 Posts |
|
|
|
|
|
|