--记录操作的示例(但要在每个表上都建,而且只能记录删除语句的前255个字符)--创建记录的日志表 create table t_log( id int identity(1,1) primary key, 工作站名 nchar(30) not null default host_name(), 操作员 sysname DEFAULT SUSER_SNAME(), 操作时间 datetime default getdate(), 事件类型 nvarchar(30), 参数 int, 执行的语句 nvarchar(255)) go--演示用的数据表 create table test(id int) go--记录操作的触发器 create trigger t_update on test for delete--insert,update,delete as insert t_log(事件类型,参数,执行的语句) exec('dbcc inputbuffer(@@spid)') go--初始化表 insert into test values(1) goupdate test set id=100 go--显示记录情况 select * from t_log go--删除演示环境 drop table t_log,test
开始--程序--MS SQLSERVER
--事件探察器(SQL Profiler)
--文件
--新建--跟踪...
--设置要跟踪的服务器的信息(连接服务器)--确定
--设置跟踪的项目...
--然后数据库的调用情况就会显示出来在跟踪项目设置中,如果不熟悉的话,一般用默认设置
筛选项目有几个可以注意一下:1.DatabaseName 同于你要检测的数据库名
2.Error 同于错误,如果经常出现某个编号的错误,则针对此错误号
3.Seccess 同于0,失败,1,成功,如果是排错,就过滤掉成功的处理
create table t_log(
id int identity(1,1) primary key,
工作站名 nchar(30) not null default host_name(),
操作员 sysname DEFAULT SUSER_SNAME(),
操作时间 datetime default getdate(),
事件类型 nvarchar(30),
参数 int,
执行的语句 nvarchar(255))
go--演示用的数据表
create table test(id int)
go--记录操作的触发器
create trigger t_update on test
for delete--insert,update,delete
as
insert t_log(事件类型,参数,执行的语句) exec('dbcc inputbuffer(@@spid)')
go--初始化表
insert into test values(1)
goupdate test set id=100
go--显示记录情况
select * from t_log
go--删除演示环境
drop table t_log,test