Question : Does MS Sql keep a record of when a database is deleted

Need to know if there is anywhere in a system table in SQL 2005 or in the event logs that can tell me who, when, why, where, or how someone deleted a database.

Answer : Does MS Sql keep a record of when a database is deleted

You would do something like this:

CREATE TRIGGER ddl_trig_database
ON ALL SERVER
FOR DROP_DATABASE
AS
    PRINT 'Database Dropped.'
    SELECT SYSTEM_USER, EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)')
GO

But you could even

INSERT INTO dbo.tblAudit (username, eventdata)
SELECT SYSTEM_USER, EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)')

You would need to create the table in the master or in a database that could be inserted into from that context, but you could keep an eye with this type of DDL trigger.

Random Solutions  
 
programming4us programming4us