SQL Server Profiler: Step by Step Guide
SQL Server Profiler: Step by Step Guide
SQL Server Profiler: Step by Step Guide
MS SQL Server Profiler is used to analyze log running queries and stored procedures.
SQL Server profiler is used to debug, troubleshoot, and monitor SQL queries and stored
procedures. You can select the events you want to monitor. You can also filter the trace
information which is helpful when trace log is very large.
Create a trace
Use SQL Server Profiler to monitor only the events in which you are interested.
Menu Path: Start ->All Programs ->Microsoft SQL Server 2005 ->Performance Tools ->SQL
Server Profiler
1 | Page
2 | Page
General Tab:
Section 1: In this section, you have to specify the name of trace, Trace provider name and trace
provider type are predefined and based upon SQL Server version.
Section 2: It is the template section. You can choose different Templates based upon requirements.
It is the configuration for trace. By default, it is Standard (Default) templates. Others templates are
SQLProfilerSP_Counts, SQLProfilerStandard, SQLProfilerTSQL, SQLProfilerTSQL_Duration,
SQLProfilerTSQL_Grouped, SQLProfilerTSQL_Replay, SQLProfilerTSQL_SPs,
and SQLProfilerTuning. You can create custom Templates by selecting different Events and Event
Class. Template file is saved with .tdf extension.
3 | Page
Section 4: You can stop trace at particular time. Check the Enable trace stop time checkbox; enter
the time to stop trace. SQL Server will automatically stop trace at defined time.
Event Tab:
An Event is an action or operation that is performed in your SQL Server 2008 Database Engine.
Some examples of Events are:
SQL Server profiler is able to trace all of these events and all these events are categorized on a
particular Event class.
In section 1, select the Events check box based upon our requirement,
section 2 will display the details of Selected events and Events class. If you check in the check box of
section 3, you will get all the list of Events and Columns in Section 1.
Section 4 is something like customization. Just click on the Column Filter Button. In this section,
you can specify some condition (like or not like).
5 | Page
By clicking on Organize Column button, the sequence of order of selected events can be changed.
Now Click on Run Button, Trace window will be displayed:
Using these windows, you will get the detailed time duration of a query and all other events
information that has been selected.
Results can be saved for future use. Or you can extract a particular query from the trace, just right
click and click on Extract Event Data, and save this as a SQL Script.
6 | Page
RPC Completed : This event includes the information about the execution of stored
procedure including the Duration, CPU, Reads, Writes together with the name of the stored
procedure that ran. This event does not fire for Transact-SQL statements that occur outside the
stored procedure
SP : stmt Completed : This event tells us when a statement within a stored procedure has
completed. It provides us events Duration, CPU, Reads, Writes. A single Stored Procedure may
contain a single or many individual statements. For example, if there are five SELECT
statements, the there will be five stmt Completed events for that stored procedure. This event
does not fire for Transact-SQL statements that occur outside the stored procedure
SQL: Batch Starting: This event id fired whenever a new Transact SQL batch begins,
whether the transact SQL statement is inside or outside a stored procedure. This event is used
because if there is any new stored procedure or Transact SQL statement, we can identify a new
chain of query related event begins.
SQL: Batch Completed: This event occurs when a Transact SQL statement completes,
whether the transact SQL statement is inside or outside a stored procedure. If the event is a
stored procedure SQL Batch Completed provides the name of the store procedure along with
the Duration, CPU, Reads, Writes of the statement
SQL: Batch Completed provides event data when a Transact-SQL statement is run outside a stored
procedure and SP : stmt Completed to see more easily is inside a stored procedure.
9 | Page
Row 1 shows the SQL: Batch starting event, it indicates when a stored procedure is called along with
its name.
Row 2 shows the showplan XML event, which provides a graphical execution plan of the T-SQL that
was executed.
Row 3 shows SP: Stmt Completed event shows the actual code that has run along with the time taken
by the event(Duration)
Row 4 shows SQL: Batch Completed event indicates that the stored procedure has completed along
with Duration, CPU, Reads, Writes for the entire stored procedure
If there is an event related to the firing of a single Transact-SQL statement that is not inside a stored
procedure.
10 | P a g e
11 | P a g e