由于项目要求,我要做到记录修改数据库的数据。记录修改人的方法已经找到了,问题是如何记录每次更新的东西?要独立用一个表来记录修改记录。具体要求:
1、对数据库A操作,然后,将有修改的过记录的原数据和新数据记录到数据表B中;
问题是:如何获取更新了哪个字段?如何去记录?
请大虾拯救我啊~~~·

解决方案 »

  1.   

    使用触发器。在表上建立insert,update,delete触发器。
    当进行修改的时候,从inserted中读取插入的数据,deleted中读取删除的数据
      

  2.   

    if object_id('tb') is not null
       drop table tb
    go
    create table tb(id int,name varchar(10))
    insert into tb
    select 1,'wang'
    go
    if object_id('tb_log') is not null
       drop table tb_log
    create table tb_log(id int ,name varchar(10),dml varchar(200))
    go
    create trigger t_tb
    on tb
    for insert ,delete,update
    as
    begin
       if not exists(select 1 from deleted)
          insert into tb_log
          select *,'insert' from inserted
       else
       if not exists(select 1 from inserted)
          insert into tb_log
          select * ,'delete' from deleted
       else
          insert into tb_log
          select * ,'update before' from deleted
          union all
          select * ,'update after' from inserted
    end
      

  3.   

    我都觉得他很变态!~!~发泄一下下~哈哈!~我开发的是B/S系统,前台的话更加复杂了……唉~~~~~~~上天啊~~
    学到东西了~~感谢HEROWANG~~~~结帖送分~哈哈~