DECLARE @dbid AS INT, @traceid AS INT;
SET @dbid = DB_ID('CCTTBR');--这里写数据库名
EXEC dbo.sp_perfworkload_trace_start
@dbid = @dbid,
@tracefile = 'c:\temp\Perfworkloaf.trc',--这里写跟踪文件放在服务器哪个位置
@traceid = @traceid OUTPUT;
--将跟踪文件里的数据读取出来,并插入单独表里
--SELECT CAST(TextData AS NVARCHAR(MAX)) AS tsql_code, Duration AS duration, t.Reads, t.Writes, CPU, t.RowCounts
--FROM sys.fn_trace_gettable('c:\temp\Perfworkloaf.trc', NULL) AS T
--WHERE Duration IS NOT NULL;