SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Tracking changes to SQL Server


Tracking changes to SQL Server

Author
Message
dwilliscp
dwilliscp
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2119 Visits: 784
I was wondering if a SQL trace could be set up to track changes to SQL Server, so I can track who is making changes and keep the Recovery Document up to date. So I would not want to track things... like users and logins. In fact I do not need to track anything below the database level, but one issue that came up today... was that someone had deleted a linked server.

Going through Profiler, I tried to build the trace... but I am not sure if my selections are correct.

-- Trying to create a trace to caputre changes to the SQL Server Instance

declare @rc int
declare @TraceID int
declare @maxfilesize bigint
declare @OutputFileName nvarchar(256)
set @maxfilesize = 10
set @OutputFileName = 'F:\tracefiles\Track_Instance_Changes' + '_' + convert(varchar(20), getdate(),112) + Replace(convert(varchar(20), getdate(),108),':','')

exec @rc = sp_trace_create @TraceID output, 0, @OutputFileName, @maxfilesize, NULL

if (@rc != 0) goto error

-- Set the events
declare @on bit
set @on = 1
exec sp_trace_setevent @TraceID, 117, 7, @on
exec sp_trace_setevent @TraceID, 117, 23, @on
exec sp_trace_setevent @TraceID, 117, 8, @on
exec sp_trace_setevent @TraceID, 117, 40, @on
exec sp_trace_setevent @TraceID, 117, 64, @on
exec sp_trace_setevent @TraceID, 117, 1, @on
exec sp_trace_setevent @TraceID, 117, 9, @on
exec sp_trace_setevent @TraceID, 117, 41, @on
exec sp_trace_setevent @TraceID, 117, 49, @on
exec sp_trace_setevent @TraceID, 117, 6, @on
exec sp_trace_setevent @TraceID, 117, 10, @on
exec sp_trace_setevent @TraceID, 117, 14, @on
exec sp_trace_setevent @TraceID, 117, 26, @on
exec sp_trace_setevent @TraceID, 117, 50, @on
exec sp_trace_setevent @TraceID, 117, 3, @on
exec sp_trace_setevent @TraceID, 117, 11, @on
exec sp_trace_setevent @TraceID, 117, 35, @on
exec sp_trace_setevent @TraceID, 117, 51, @on
exec sp_trace_setevent @TraceID, 117, 12, @on
exec sp_trace_setevent @TraceID, 117, 44, @on
exec sp_trace_setevent @TraceID, 117, 60, @on
exec sp_trace_setevent @TraceID, 117, 5, @on
exec sp_trace_setevent @TraceID, 117, 21, @on
exec sp_trace_setevent @TraceID, 117, 29, @on
exec sp_trace_setevent @TraceID, 117, 37, @on
exec sp_trace_setevent @TraceID, 129, 7, @on
exec sp_trace_setevent @TraceID, 129, 23, @on
exec sp_trace_setevent @TraceID, 129, 8, @on
exec sp_trace_setevent @TraceID, 129, 40, @on
exec sp_trace_setevent @TraceID, 129, 64, @on
exec sp_trace_setevent @TraceID, 129, 1, @on
exec sp_trace_setevent @TraceID, 129, 41, @on
exec sp_trace_setevent @TraceID, 129, 49, @on
exec sp_trace_setevent @TraceID, 129, 6, @on
exec sp_trace_setevent @TraceID, 129, 10, @on
exec sp_trace_setevent @TraceID, 129, 14, @on
exec sp_trace_setevent @TraceID, 129, 26, @on
exec sp_trace_setevent @TraceID, 129, 34, @on
exec sp_trace_setevent @TraceID, 129, 50, @on
exec sp_trace_setevent @TraceID, 129, 3, @on
exec sp_trace_setevent @TraceID, 129, 11, @on
exec sp_trace_setevent @TraceID, 129, 35, @on
exec sp_trace_setevent @TraceID, 129, 51, @on
exec sp_trace_setevent @TraceID, 129, 4, @on
exec sp_trace_setevent @TraceID, 129, 12, @on
exec sp_trace_setevent @TraceID, 129, 28, @on
exec sp_trace_setevent @TraceID, 129, 60, @on
exec sp_trace_setevent @TraceID, 129, 5, @on
exec sp_trace_setevent @TraceID, 129, 21, @on
exec sp_trace_setevent @TraceID, 129, 29, @on
exec sp_trace_setevent @TraceID, 129, 37, @on
exec sp_trace_setevent @TraceID, 178, 7, @on
exec sp_trace_setevent @TraceID, 178, 23, @on
exec sp_trace_setevent @TraceID, 178, 8, @on
exec sp_trace_setevent @TraceID, 178, 40, @on
exec sp_trace_setevent @TraceID, 178, 64, @on
exec sp_trace_setevent @TraceID, 178, 1, @on
exec sp_trace_setevent @TraceID, 178, 41, @on
exec sp_trace_setevent @TraceID, 178, 49, @on
exec sp_trace_setevent @TraceID, 178, 6, @on
exec sp_trace_setevent @TraceID, 178, 10, @on
exec sp_trace_setevent @TraceID, 178, 14, @on
exec sp_trace_setevent @TraceID, 178, 26, @on
exec sp_trace_setevent @TraceID, 178, 34, @on
exec sp_trace_setevent @TraceID, 178, 50, @on
exec sp_trace_setevent @TraceID, 178, 3, @on
exec sp_trace_setevent @TraceID, 178, 11, @on
exec sp_trace_setevent @TraceID, 178, 35, @on
exec sp_trace_setevent @TraceID, 178, 51, @on
exec sp_trace_setevent @TraceID, 178, 4, @on
exec sp_trace_setevent @TraceID, 178, 12, @on
exec sp_trace_setevent @TraceID, 178, 28, @on
exec sp_trace_setevent @TraceID, 178, 60, @on
exec sp_trace_setevent @TraceID, 178, 21, @on
exec sp_trace_setevent @TraceID, 178, 29, @on
exec sp_trace_setevent @TraceID, 178, 37, @on
exec sp_trace_setevent @TraceID, 130, 7, @on
exec sp_trace_setevent @TraceID, 130, 23, @on
exec sp_trace_setevent @TraceID, 130, 39, @on
exec sp_trace_setevent @TraceID, 130, 8, @on
exec sp_trace_setevent @TraceID, 130, 40, @on
exec sp_trace_setevent @TraceID, 130, 64, @on
exec sp_trace_setevent @TraceID, 130, 1, @on
exec sp_trace_setevent @TraceID, 130, 41, @on
exec sp_trace_setevent @TraceID, 130, 49, @on
exec sp_trace_setevent @TraceID, 130, 10, @on
exec sp_trace_setevent @TraceID, 130, 26, @on
exec sp_trace_setevent @TraceID, 130, 34, @on
exec sp_trace_setevent @TraceID, 130, 42, @on
exec sp_trace_setevent @TraceID, 130, 50, @on
exec sp_trace_setevent @TraceID, 130, 3, @on
exec sp_trace_setevent @TraceID, 130, 11, @on
exec sp_trace_setevent @TraceID, 130, 35, @on
exec sp_trace_setevent @TraceID, 130, 43, @on
exec sp_trace_setevent @TraceID, 130, 51, @on
exec sp_trace_setevent @TraceID, 130, 4, @on
exec sp_trace_setevent @TraceID, 130, 12, @on
exec sp_trace_setevent @TraceID, 130, 28, @on
exec sp_trace_setevent @TraceID, 130, 60, @on
exec sp_trace_setevent @TraceID, 130, 21, @on
exec sp_trace_setevent @TraceID, 130, 29, @on
exec sp_trace_setevent @TraceID, 130, 37, @on
exec sp_trace_setevent @TraceID, 130, 6, @on
exec sp_trace_setevent @TraceID, 130, 14, @on
exec sp_trace_setevent @TraceID, 118, 7, @on
exec sp_trace_setevent @TraceID, 118, 23, @on
exec sp_trace_setevent @TraceID, 118, 8, @on
exec sp_trace_setevent @TraceID, 118, 40, @on
exec sp_trace_setevent @TraceID, 118, 64, @on
exec sp_trace_setevent @TraceID, 118, 1, @on
exec sp_trace_setevent @TraceID, 118, 9, @on
exec sp_trace_setevent @TraceID, 118, 41, @on
exec sp_trace_setevent @TraceID, 118, 49, @on
exec sp_trace_setevent @TraceID, 118, 6, @on
exec sp_trace_setevent @TraceID, 118, 10, @on
exec sp_trace_setevent @TraceID, 118, 14, @on
exec sp_trace_setevent @TraceID, 118, 26, @on
exec sp_trace_setevent @TraceID, 118, 34, @on
exec sp_trace_setevent @TraceID, 118, 50, @on
exec sp_trace_setevent @TraceID, 118, 3, @on
exec sp_trace_setevent @TraceID, 118, 11, @on
exec sp_trace_setevent @TraceID, 118, 35, @on
exec sp_trace_setevent @TraceID, 118, 51, @on
exec sp_trace_setevent @TraceID, 118, 4, @on
exec sp_trace_setevent @TraceID, 118, 12, @on
exec sp_trace_setevent @TraceID, 118, 28, @on
exec sp_trace_setevent @TraceID, 118, 60, @on
exec sp_trace_setevent @TraceID, 118, 5, @on
exec sp_trace_setevent @TraceID, 118, 21, @on
exec sp_trace_setevent @TraceID, 118, 29, @on
exec sp_trace_setevent @TraceID, 118, 37, @on
exec sp_trace_setevent @TraceID, 176, 7, @on
exec sp_trace_setevent @TraceID, 176, 23, @on
exec sp_trace_setevent @TraceID, 176, 8, @on
exec sp_trace_setevent @TraceID, 176, 40, @on
exec sp_trace_setevent @TraceID, 176, 64, @on
exec sp_trace_setevent @TraceID, 176, 1, @on
exec sp_trace_setevent @TraceID, 176, 9, @on
exec sp_trace_setevent @TraceID, 176, 41, @on
exec sp_trace_setevent @TraceID, 176, 49, @on
exec sp_trace_setevent @TraceID, 176, 10, @on
exec sp_trace_setevent @TraceID, 176, 26, @on
exec sp_trace_setevent @TraceID, 176, 34, @on
exec sp_trace_setevent @TraceID, 176, 50, @on
exec sp_trace_setevent @TraceID, 176, 3, @on
exec sp_trace_setevent @TraceID, 176, 11, @on
exec sp_trace_setevent @TraceID, 176, 35, @on
exec sp_trace_setevent @TraceID, 176, 51, @on
exec sp_trace_setevent @TraceID, 176, 4, @on
exec sp_trace_setevent @TraceID, 176, 12, @on
exec sp_trace_setevent @TraceID, 176, 28, @on
exec sp_trace_setevent @TraceID, 176, 60, @on
exec sp_trace_setevent @TraceID, 176, 21, @on
exec sp_trace_setevent @TraceID, 176, 29, @on
exec sp_trace_setevent @TraceID, 176, 37, @on
exec sp_trace_setevent @TraceID, 176, 45, @on
exec sp_trace_setevent @TraceID, 176, 6, @on
exec sp_trace_setevent @TraceID, 176, 14, @on
exec sp_trace_setevent @TraceID, 176, 46, @on


-- Set the Filters
declare @intfilter int
declare @bigintfilter bigint

-- Set the trace status to start
exec sp_trace_setstatus @TraceID, 1

-- display trace id for future references
select TraceID=@TraceID
goto finish

error:
select ErrorCode=@rc

finish:
go
GilaMonster
GilaMonster
SSC Guru
SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)

Group: General Forum Members
Points: 220347 Visits: 46279
Have you considered DDL triggers?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


dwilliscp
dwilliscp
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2119 Visits: 784
I take it.. from your reply... that it is possible to put triggers on Instance level settings.. like Linked Servers, Job Log settings, ect... not sure how to do that, I do know how to create a trigger on a table... I guess Microsoft is storing that data someplace, but not sure where... or even if it is one of the system databases that we have access to (msdb, or master would be the only two that I would guess this data is stored in... that is not a hidden database)
GilaMonster
GilaMonster
SSC Guru
SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)

Group: General Forum Members
Points: 220347 Visits: 46279
System tables in the master database, but no, I was not suggesting DML triggers on the system tables.

DDL triggers
http://msdn.microsoft.com/en-us/library/ms190989%28v=sql.105%29.aspx

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


dwilliscp
dwilliscp
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2119 Visits: 784
Thanks for your help.. I will review your link next week! Cool
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search