用SQL语句来建立跟踪的问题

2016-01-29 16:43 11 1 收藏

用SQL语句来建立跟踪的问题,用SQL语句来建立跟踪的问题

【 tulaoshi.com - SQLServer 】

下面是我用SQL的事件探察器设置跟踪,并生成的SQL脚本
 现在有几个问题:
 
1.这个跟踪不会产生数据,用:
  select * from ::fn_trace_getinfo(1)
 可以看到状态是在运行,但 c:test.trc 始终是空文件 
 
2.在事件探察器中设置筛选时,ObjectType 的说明是对应sysobjects 表的 type 列,该列是字符型,但我输入字符时要求是数字,这个数字从那里查?
 
 3.如果只产生对 insert,update,delete 语句成功的跟踪事件应该如何设置呢? 在 事件探察器 中无相关设置,用语句设置的话只找到事件号 28, 在执行 SELECT、INSERT 或 UPDATE 语句之前发生
 
 4.用事件探察器建立的跟踪,可以将跟踪结果保存到表中,但我下面生成的SQL脚本却不支持这个功能
--*/
/****************************************************/
/* Created by: SQL Profiler                         */
/* Date: 2004/06/19  16:50:05         */
/****************************************************/

-- Create a Queue
declare @rc int
declare @TraceID int
declare @maxfilesize bigint
set @maxfilesize = 5 
-- Please replace the text InsertFileNameHere, with an appropriate
-- filename prefixed by a path, e.g., c:MyFolderMyTrace. The .trc extension
-- will be appended to the filename automatically. If you are writing from
-- remote server to local drive, please use UNC path and make sure server has
-- write access to your network share
exec @rc = sp_trace_create @TraceID output, 0, N’c:test’, @maxfilesize, NULL 
if (@rc != 0) goto error
-- Client side File and Table cannot be scripted
-- Writing to a table is not supported through the SP’s
-- Set the events
declare @on bit
set @on = 1
exec sp_trace_setevent @TraceID, 12, 1, @on
exec sp_trace_setevent @TraceID, 12, 12, @on
exec sp_trace_setevent @TraceID, 12, 14, @on

-- Set the Filters
declare @intfilter int
declare @bigintfilter bigint
exec sp_trace_setfilter @TraceID, 10, 0, 7, N’SQL Profiler’
set @intfilter = 100
exec sp_trace_setfilter @TraceID, 22, 0, 4, @intfilter
set @intfilter = 1
exec sp_trace_setfilter @TraceID, 23, 1, 0, @intfilter
exec sp_trace_setfilter @TraceID, 35, 1, 6, N’pubs’

-- Set the trace status to start
exec sp_trace_setstatus @TraceID, 1
-- display trace id for future references
select TraceID=@TraceID
goto finish
error: 
select ErrorCode=@rc
finish: 
go

来源:https://www.tulaoshi.com/n/20160129/1499387.html

延伸阅读
新建表: create table [表名] ( [自动编号字段] int IDENTITY (1,1) PRIMARY KEY , [字段1] nVarChar(50) default '默认值' null , [字段2] ntext null , [字段3] datetime, [字段4] money null , [字段5] int defaul...
说明:复制表(只复制结构,源表名:a 新表名:b) select * into b from a where 11 说明:拷贝表(拷贝数据,源表名:a 目标表名:b) insert into b(a, b, c) select d,e,f from b; 说明:显示文章、提交人和最后回复时间 select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title...
CREATE procedure dbo.select_a     @b varchar(50),     @c varchar(50),     @d varchar(50),     @e varchar(50) as declare @strsql varchar(5000) ; set @strsql='select * from&nb...
标签: SQLServer
下列语句部分是Mssql语句,不可以在access中使用。 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK) 首先,简要介绍基础语句: 1、说明:创建数据库 CREATE DATABASE database-name 2、说明:删除数据库 drop database ...
UPDATE Friend set Name = REPLACE(Name,'脚本,'脚本之家www.jb51.net')超级简单 

经验教程

32

收藏

11
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部