patternsqlModerate
Logging queries and other T-SQL
Viewed 0 times
loggingsqlandqueriesother
Problem
I would like to know if SQL Server 2008 R2 has a default logging scheme for
If yes, where can I see it? If not, how could I set it up?
SELECT statements (or any other T-SQL for that matter).If yes, where can I see it? If not, how could I set it up?
Solution
By default, SQL Server activity is not logged the way you expect. Some write activity is recorded in the Transaction Log, but this also depends on how your databases are set up.
There are four main options for tracking SELECT activity on a server:
-
You can use SQL Server Profiler to connect to your server and watch for specific activity as it happens.
-
You can create a server-side trace to log activity to a trace file on the server, which can then be read by SQL Server Profiler, or by using fn_trace_gettable to load it into a table for further analysis.
-
You can use Extended Events, which offers more functionality than server-side traces, and which Microsoft recommends instead of server-side traces starting with SQL Server 2012.
-
You could use C2 audit mode.
You can use SQL Server Profiler to set up your trace (choose the specific events, filters, etc. that you want), then script it out using the File menu and execute it on the server to create a server-side trace, as described here.
There are four main options for tracking SELECT activity on a server:
-
You can use SQL Server Profiler to connect to your server and watch for specific activity as it happens.
-
You can create a server-side trace to log activity to a trace file on the server, which can then be read by SQL Server Profiler, or by using fn_trace_gettable to load it into a table for further analysis.
-
You can use Extended Events, which offers more functionality than server-side traces, and which Microsoft recommends instead of server-side traces starting with SQL Server 2012.
-
You could use C2 audit mode.
You can use SQL Server Profiler to set up your trace (choose the specific events, filters, etc. that you want), then script it out using the File menu and execute it on the server to create a server-side trace, as described here.
Context
StackExchange Database Administrators Q#40960, answer score: 19
Revisions (0)
No revisions yet.