Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2006
    Posts
    1

    Unanswered: How do i update I record in a table via a Trigger?

    Am in a small fix. my Trigger is updating my entire table records , i don't want that, i want to update a column in the record that is updated by my application using a trigger that tracks updates on that table.

    Is there a way i can track the updated record on my table and then update a field in that record through my TRIGGER?

    My database is MSSQLServer2005 Enterprise Edition..


    Below is my code

    CREATE TRIGGER [TR_Employee]
    ON [Test_1_1].[dbo].[Employee]
    For UPDATE
    Not For Replication
    AS
    BEGIN

    Update Employee set Last_Changed = (select getDate())

    END
    Go


    Yemi

  2. #2
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Go to BOL. Do an indexed search for trigger. Double-click on AFTER and choose triger execution. Read the entry. Double click on "Using the Inserted and Deleted tables". Read the article. Ta-da ... you have your answer!

    -- This is all just a Figment of my Imagination --

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    I'm guessing that you allow access to the database by means other than stored procedures.

    If iy ws sproc access only, then you wouldn't have this problem
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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