Tuesday, December 3, 2013

Find SQL Traces, currently running


SELECT * FROM sys.traces -- Will show all the traces

You will get so many details by running the above statement regarding the current traces.
By default one trace is running.
You can see the location/Path where the trace file being sitting, Start time, Stop time, How much max. size the trace file holds up to, in how many files it Can hold the data end so on.

Note: You can give your own size and own number of files while starting the Trace.

SELECT * FROM fn_trace_getinfo(0) -- Show all traces

It will give you minimum but almost all important fields information as result. But you have to process the trace number as Input in the function.

SELECT * FROM fn_trace_getinfo(NULL)
will to same as above.

If you decided to Stop/Delete a trace which is currently running, you can use below commands.(Note: You have to provide the trace id)

sp_trace_setstatus  @traceid =  2,  @status =  0    -- It will stop the trace by providing Traceid..

 Even though the trace is stopped, it still showing up on the traces list. You can completely delete that by using following command.

sp_trace_setstatus  @traceid =  2,  @status =  2   -- It will delete the trace from the list by providing Traceid..