利用触发器能否知道哪条记录被修改?

解决方案 »

  1.   

    可以。
    建一个触发器 AFTER update 
    old.列名 就是修改的列
    当然也可以在修改前触发
      

  2.   

    可以。。
    create trigger tr_t on 你的表名
    for update
    as
    begin 
       declare @n int
       set @n=(select id from inserted )
       print '你表中ID为'+rtrim(@n)+'已经修改了!!'
    end
      

  3.   

    可以不用触发器,用output ,联机帮助的例子USE AdventureWorks;
    GO
    DECLARE @MyTableVar table(
        EmpID int NOT NULL,
        OldVacationHours int,
        NewVacationHours int,
        ModifiedDate datetime);
    UPDATE TOP (10) HumanResources.Employee
    SET VacationHours = VacationHours * 1.25 
    OUTPUT INSERTED.EmployeeID,
           DELETED.VacationHours,
           INSERTED.VacationHours,
           INSERTED.ModifiedDate
    INTO @MyTableVar;
    --Display the result set of the table variable.
    SELECT EmpID, OldVacationHours, NewVacationHours, ModifiedDate
    FROM @MyTableVar;
    GO
    --Display the result set of the table.
    --Note that ModifiedDate reflects the value generated by an
    --AFTER UPDATE trigger.
    SELECT TOP (10) EmployeeID, VacationHours, ModifiedDate
    FROM HumanResources.Employee;
    GO
      

  4.   

    可以
    create trigger tr_t on 你的表名
    for update
    as
    begin 
        insert yourtable
        select *
        from inserted
    end
      

  5.   

    http://blog.csdn.net/fredrickhu/archive/2009/10/21/4708906.aspxLOOK THIS BLOG
      

  6.   

    inserted更新之后的数据,Deleted更新之前的数据吧,update在底层应该是先DELETE在Insert
      

  7.   


    create trigger tr_t on 你的表名
    for update
    as
    begin 
        insert yourtable
        select *
        from deleted
    end
      

  8.   

    可以,在触发器中
    修改记录时,旧的未修改的记录放于deleted表中
    新的已修改的记录放于inserted表中,根据此两表与主键,可确定修改了那些记录,字段