急!sql触发器监控数据改动(100分求,有追分)

来源:百度知道 编辑:UC知道 时间:2024/06/11 00:55:03
有多个数据库,库名不定,库里面有若干表。

求高手写个触发器程序,要求监控每个表的数据变动。
当有添加,删除,修改数据的动作时。
记录“动作时间”,“sql动作”和“记录号id”到T_Record表。
并且发送邮件
忘了,触发器针对的是表。
那就在每张表建个触发器吧。
这个触发器怎么写??比如是subject表
还要发邮件。

触发器是建在表上的,怎么能监控所有的表呢。
除非在所有表建触发器,这样话数据库的性能得
不到保障
还有即使你所有表建了触发器,如果用户新增一张表
还是不能监控到。

期待楼下是不是有什么好方法

---补充
--建表
create table subject
(
col1 int
)
create table t_record
(
action_id numeric(10) identity(1,1),
action_time datetime,
action varchar(10)
)
--触发器
create trigger trig_subject on subject
for insert,update,delete
as
begin
declare @inserted int
declare @deleted int
select @inserted = count(*) from inserted
select @deleted = count(*) from deleted

if @inserted > 0 and @deleted > 0
begin
insert into t_record values(getdate(),'update')
end
else if @inserted > 0 and @deleted = 0
begin
insert into t_record values(getdate(),'insert')
end
else if @inserted = 0 and @deleted > 0
begin
insert into t_record values