Are you one looking to find answer for questions like below.,
· How to find who dropped a database?
· How to find who created the database?
· How to find who altered the database?
· How to find who altered the database configurations?
· How to find who dropped the schema?
· How to find who altered the schema?
· How to find who altered the server configuration?
· How to find who modified the login?
· How to find who modified the table?
If it is then, are you wondering is that possible on SQL Server?
Yes, SQL Server can beginning from version SQL Server 2005 onwards.
That is where SQL Server Default trace come into picture.
What is SQL Server Default Trace?
Default trace provides troubleshooting assistance to database administrators by ensuring that they have the log data necessary to diagnose problems the first time they occur.
To get the default trace options
SELECT * FROM ::fn_trace_getinfo(default)
To know what is audited on default trace
SELECT Trc.EventID, Trc.ColumnID, Evt.name as Event_Description, Col.name as Column_Description
FROM ::fn_trace_geteventinfo(1) Trc
JOIN sys.trace_events Evt ON Trc.eventID = Evt.trace_event_id
Below is the screenshot “Schema Changes History” of Standard Reports at Server Level.
See that “it shows the event of Drop and Alter of the database
The same can be queried from SQL Server Default Trace like;
select * from fn_trace_gettable('C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Log\log.trc',DEFAULT)
where EventClass in (46,47,164) and EventSubclass = 0 and DatabaseID <> 2
Default trace can be queried to find answers on
- To finmd the Create / Alter / Drop i.e., DDL changes at Database,Schema and Object level
- To find the configuration changes at SQL Server Instance, Database, Schema and Object Level
- To find Login creation , modifications and failures
- To find performance issues like missing of statistics, join predicate, hash or sort warnings
- Database file growth or shrinkage
- DBCC operations
Points to ponder
- Default trace is a Server Side trace and it is enable by default.
- Default trace properties can not be modified, other than enabling and disabling of this trace.
- Default trace by default enabled and stored on the “Log” folder
- Default trace file will be created newly on start of the SQL Server service.
- A single trace file can store up to 20 MB, when it is full new file will be created.
- SQL Server would maintain 5 default trace file, where the file with highest number is the latest.
- Default trace is light weight and it is not replacement for DDL Trigger. Default trace log only basic information, when detailed information needed DDL trigger is the option.