How does one read SQL Profiler Trace into an SQL table?

Source: Internet
Author: User
Tags table definition

SQL Profiler is a very powerful tool. It is fine to read the analysis principles in order. However, if you want to analyze complicated situations, you need more things.

Here we will introduce a method to operate Profiler Trace like an SQL table, so that you can use select to view the information you are interested in.

 

To do this, you can use a built-in function named fn_trace_gettable.

select * from fn_trace_gettable('c:\MyTraceFile.trc', default)

The first parameter is obviously the path of the profiler trace on the disk.

The second parameter indicates the number of files to be read. The default value is-1, meaning all files must be read.

 

Although you can use this function to read the trace file each time, there is a better way, that is, to import the data in the file into a table and then query the table, this is much faster than reading files every time.

The method is as follows:

select IDENTITY(BIGINT, 1, 1) AS RowNumber, * into MyTraceTablefrom fn_trace_gettable('D:\MyProfilerTrace.trc', default)where 1 = 0  --just create the table without any data

 

Once you have created a table definition, the next step is to insert data into the table.

insert into MyTraceTableselect * from fn_trace_gettable('D:\MyProfilerTrace.trc', default)

 

Add

==============

After reading the table, you can try to run the following statement to select the statement or stored procedure with the longest running time.

select top 50 T.RowNumber, TE.name,T.duration DurationMicroSeconds,T.TextData     from MyTraceTable T        join sys.trace_events TE ON T.EventClass = TE.trace_event_idwhere eventclass <> 15order by T.durationdesc

 

Here you can see the row number. use SQL profiler to open the trace file, you can locate the context of the problem statement.

 

References:

Reading a SQL Profiler Trace file

Http://sql2005ted.blogspot.com/2009/06/reading-sql-profiler-trace-file.html

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.