question

siera_gld avatar image
siera_gld asked

Find UserID that created primary key

I need to find a user that created a primary key on a table. Is there a way to get this from system views?
auditsysviews
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
what version of SQL Server?
0 Likes 0 ·
siera_gld avatar image siera_gld commented ·
I am working with 2008 R2 Enterprise Edition
0 Likes 0 ·

1 Answer

·
RichardFryar avatar image
RichardFryar answered
The default trace will show you, provided that it happened recently. On a busy server with lots of activity the default trace may not help as it only keeps the last 100MB of data. Replace pk_t in this script with the name of the primary key, and keep your fingers crossed! use master; set nocount on; declare @path nvarchar(500) select @path = convert(nvarchar(500), value) from ::fn_trace_getinfo(0) i join sys.traces t on t.id = i.traceid where t.is_default = 1 and i.property = 2 if @path is not null begin select @path = reverse(substring(reverse(@path), charindex('\', reverse(@path)), 500)) + N'log.trc' select df.StartTime, e.name, v.subclass_name, df.ApplicationName, df.DatabaseName, df.LoginName, df.ObjectName, df.HostName from ::fn_trace_gettable(convert(nvarchar(255), @path), 0) df join sys.trace_events e ON df.EventClass = e.trace_event_id left join sys.trace_subclass_values v on v.trace_event_id = e.trace_event_id and v.subclass_value = df.EventSubClass where e.category_id = 5 and df.ObjectName = 'pk_t' order by df.StartTime desc end
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

siera_gld avatar image siera_gld commented ·
This may work but only if it were recently done...not in my case :(
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.