想做一个日志系统记录用户读对据库的操作,请做过的给点思路吧?(10分)

  • 主题发起人 主题发起人 ruoxi_shuai
  • 开始时间 开始时间
R

ruoxi_shuai

Unregistered / Unconfirmed
GUEST, unregistred user!
想做一个日志系统记录用户对据库的操作,请做过的给点思路吧?
 
建张日志表<br>然后insert update delete啥的<br>自己生成数据插到日志表里呗
 
比如在保存按钮里,当用户点了保存后,执行完必须的操作代码后,接着你将保存前的数据和保存后的数据都给插入到你的日志表里
 
用触发器很容易解决...<br>如:<br>CREATE TRIGGER TResult_D &nbsp;ON dbo.TResult <br>FOR DELETE<br>AS<br>&nbsp; &nbsp;insert TResult_bb &nbsp;SELECT a.*,b.Result_data ,'删除',getdate()<br>&nbsp; &nbsp; &nbsp;from deleted &nbsp;a &nbsp;LEFT &nbsp;JOIN<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TResult_data b &nbsp;ON a.Result_ID = b.Result_ID<br>CREATE TRIGGER TResult_I &nbsp;ON dbo.TResult <br>FOR INSERT<br>AS<br>&nbsp; &nbsp;insert TResult_bb &nbsp;SELECT a.*,b.Result_data ,'增加',getdate()<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM inserted &nbsp;a &nbsp;LEFT &nbsp;JOIN<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TResult_data b &nbsp;ON a.Result_ID = b.Result_ID<br><br>CREATE TRIGGER TResult_M &nbsp;ON dbo.TResult <br>FOR UPDATE<br>AS<br>&nbsp; &nbsp;IF update(tester) or &nbsp;update(Approver)<br>&nbsp; &nbsp;insert TResult_bb &nbsp;SELECT a.*,b.Result_data ,'修改',getdate()<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM inserted &nbsp;a &nbsp;LEFT &nbsp;JOIN<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TResult_data b &nbsp;ON a.Result_ID = b.Result_ID
 
前提要建张日志表,以上是对表内的数据当在Delete,Insert,Update时分别做相应的处理.
 
写个执行SQL的日志类阿<br>执行前先把SQL存到日志表就完了
 
后退
顶部