A script to start and set up a trace example we can use script to trace stored procedures, of course, to understand the specific syntax of these stored procedures and parameters of the meaning of these syntax and parameter meaning please check online Help. Take a look at the following example:
/*******************************************/
/* Created by:sql Profiler * *
* DATE:2004/06/19 16:50:05 * *
/*******************************************/
--Create a Queue
DECLARE @rc int
DECLARE @TraceID int
DECLARE @maxfilesize bigint
Set @maxfilesize = 5
--Please replace the text insertfilenamehere and an appropriate
--filename prefixed by a path, e.g, c:\MyFolder\MyTrace. The. trc extension
---would be appended to the filename automatically. If you are are writing from
--Remote server to local drive, "use UNC path and make sure server has
--Write access to your network share
exec @rc = sp_trace_create @TraceID output, 0, N ' c:\test ', @maxfilesize, NULL
if (@rc!= 0) Goto Error
--Client side File and Table cannot be scripted
--writing to a table isn't supported through the SP ' s
--Set The events
DECLARE @on bit
Set @on = 1
exec sp_trace_setevent @TraceID, 1, @on
exec sp_trace_setevent @TraceID, @on
exec sp_trace_setevent @TraceID, @on
--Set The Filters
DECLARE @intfilter int
DECLARE @bigintfilter bigint
exec sp_trace_setfilter @TraceID, 0, 7, N ' SQL Profiler '
Set @intfilter = 100
exec sp_trace_setfilter @TraceID, 0, 4, @intfilter
Set @intfilter = 1
EXEC sp_trace_setfilter @TraceID, 1, 0, @intfilter
EXEC sp_trace_setfilter @TraceID, 1, 6, N ' pubs '
--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