How to identify the ID of row which has been modified?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mai Phuong
    New Member
    • Sep 2009
    • 25

    How to identify the ID of row which has been modified?

    Hi all,

    I have table Demo:

    Code:
    CREATE TABLE Demo
    (
    ID               int              PRIMARY KEY,
    Name         char(50),
    BeModified  int             DEFAULT(0)
    )
    Whenever [Name] is updated, [BeModified] will be set to 1.

    I think I should create an TRIGGER AFTER UPDATE

    Code:
    CREATE TRIGGER UpdateRow
    
    ON Demo
    
    AFTER UPDATE
    
    UPDATE Demo
    
    Set BeModified = 1 WHERE ID = [B]"???"[/B]
    My problem is I do not know how to identify the ID of row which has been modified.

    Have you got any suggestion for me?

    Thank you so much!
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Use the DELETED and INSERTED tables.

    Happy Coding!!!

    --- CK

    Comment

    • Mai Phuong
      New Member
      • Sep 2009
      • 25

      #3
      I am sorry to bother you but could you explain it more specific?

      I did something to understand more about inserted & deleted table, but I get the message "Invalid object name 'inserted'."

      Comment

      • Mai Phuong
        New Member
        • Sep 2009
        • 25

        #4
        I did it, just by using inserted table.

        Thanks for your helping!

        Comment

        Working...