SQL Server Trace 说明

介绍

sql server 2005 不仅支持sql server profiler 捕捉trace,也可以自己调用系统存储过程写程序手工创建trace。

存储过程

Returns information about a specified trace or all existing traces.

---SELECT * FROM ::fn_trace_getinfo(defalut)

---SELECT * FROM ::fn_trace_getinfo(1)

Returns information about the filters applied to a specified trace.

---SELECT * FROM ::fn_trace_getfilterinfo(11)

Returns trace file information in a table format. This system function provides a mechanism for querying trace data stored in a file (trace_filename.trc). fn_trace_gettable can be used in a SELECT...INTO statement to load the data in the file into a SQL Server table.

---SELECT * FROM ::fn_trace_gettable('\\NPP-DBAMSQL1\d$\profiler\te.trc',1)

---SELECT * FROM ::fn_trace_geteventinfo('\\NPP-DBAMSQL1\d$\profiler\te.trc',1)

注意:

a: Like %select%

b: 为SQL Server2005创建模板,保存时应注意选上 SQL Server2005,因默认是SQL Server2000

c: 最下面一张图,显示的SQL Script功能,可以输出trace文件中的SQL代码

以下是通过sql server profiler创建sql server trace的步骤:

1 创建Trace模板

2 点后出现Trace模板界面

3 点Trace模板上Events,选择要捕捉的事件

4 点Data Columns,选择你希望显示的数据列

5 点Filters,添加筛选选项

6 点Save As保存模板

7 使用上面建立的模板创建新的Trace

 

原文地址:https://www.cnblogs.com/shined/p/1298174.html