Loading SQL Profiler trace (.trc) files into a table

Problem:   How to load SQL Profiler trace (.trc) files into a table?

Server traces can produce a large amount of trace data that is stored in multiple trace (.trc) files.  They can be loaded into a table by going through SQL Profiler (2005 or 2000) but that’s a cumbersome manual process.  It would be great if all the trace files from a profiler run could be loaded at once.

Solution: Use fn_trace_getfile, which will load all the files in a trace at once.

fn_trace_getfile is a system user-defined function that loads all the trace files at once. Here’s an example:

select into MyTraceTable
from::fn_trace_gettable (‘c:\temp\myTracefile.trc’, 999)

This will load up to 999 trace files into the table MyTraceTable.  Something else that makes saving traces easier is making each trace file larger.  Remember, they compress very well (RAR compression is even better on these files than ZIP) so even a 25 Megabyte trace file can be e-mailed after it’s compressed.