How to: Create a Trace (Transact-SQL)
This topic describes how to use stored procedures to create a trace.
To create a trace
Execute sp_trace_create with the required parameters to create a new trace. The new trace will be in a stopped state (status is 0).
Execute sp_trace_setevent with the required parameters to select the events and columns to trace.
Optionally, execute sp_trace_setfilter to set any or a combination of filters.
sp_trace_setevent and sp_trace_setfilter can be executed only on existing traces that are stopped.
Important
Unlike regular stored procedures, parameters of all SQL Server Profiler stored procedures (sp_trace_xx) are strictly typed and do not support automatic data type conversion. If these parameters are not called with the correct input parameter data types, as specified in the argument description, the stored procedure returns an error.
See Also
Other Resources
sp_trace_create (Transact-SQL)
sp_trace_setevent (Transact-SQL)
sp_trace_setfilter (Transact-SQL)