Question

Is there a built in way in SQL Server 2005 to audit things specifically like deleting a stored procedure? Is there a history table that I can query? We have a mystery sproc that has disappeared a few times now.

Was it helpful?

Solution

You can build this using DDL triggers:

http://msdn.microsoft.com/en-us/library/ms190989.aspx

OTHER TIPS

Only if you use DDL triggers or use profiler to trace text "%DROP%PROC%procname%"

Note that in SQL Server 2008 they also now have AUDIT to replace Profiler Traces for auding activities. It is similar but has its own configuration UI and UI to view results

You can setup a profiler trace to capture the Audit Schema Object Management event and filter based on the database name you care about. Any time an object in the schema is created, dropped, edited it will fire an event in profiler that includes the person who did the change and the name of the stored procedure.

You will want at least these profiler columns: ApplicationName - name of app user was running when they made change DatabaseName - Databse containing the object changed EventSubClass - Type of action shows Alter, Modify, Drop, Create etc LoginName - user making change ObjectName - object affected

[late one but adds details on how to see who made the change even before auditing system is put into place]

Others have already covered different ways you can start auditing data in order to monitor future changes but if you originally didn’t have any auditing system in place then it’s very difficult to find out who did what and when historically.

Only option is to try reading transaction log assuming database is in full recovery mode. Problem is that this is not supported by default. Options are:

  • Third party tools such as ApexSQL Log or Quest Toad
  • Undocumented functions such as DBCC LOG or fn_dblog

See these topics for more details:

How to view transaction log in SQL Server 2008

SQL Server Transaction Log Explorer/Analyzer

How to see query history in SQL Server Management Studio

I agree. It can be the SQL Server profiler with filters. The DDL triggers existed in SQL Server. You could create something like this:

 CREATE TRIGGER ddl_drop_procedure 
    ON DATABASE 
    FOR DROP_PROCEDURE
   AS 
     RAISERROR ('You deleted a stored procedure',10, 1)

   GO

The other option is to use third party tools like Auto Audit from codeplex, or apexSQL trigger.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top