Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70

    Unanswered: Trigger - Current record ?

    CREATE TRIGGER test ON [Table_1]
    FOR UPDATE
    AS
    UPDATE [Table_1]
    set [Field_1] =SUSER_SNAME()

    This trigger update all record, I want to update only the current record which is currenty update. How I cant to this ?

    Sorry for my english

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    When records are added to a table, a copy of the records inserted or modified is stored in a virtual temporary table called "Inserted", which has the same column structure as the actual data table. You can reference this virtual table to examine or filter based on the records that were inserted:

    CREATE TRIGGER test ON [Table_1]
    FOR UPDATE
    AS
    UPDATE [Table_1]
    set [Field_1] =SUSER_SNAME()
    from [Table_1]
    inner join Inserted on [Table_1].[PrimaryKey] = Inserted.[PrimaryKey]

    Look up Triggers in Books Online and read about both the Inserted and Deleted virtual tables.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70
    Thank you
    I don't know about "Inserted" table, Now I understand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •