Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:56:06+00:00 2026-05-24T00:56:06+00:00

I need a trigger that updates a table row field if one or more

  • 0

I need a trigger that updates a table row field if one or more fields of that row is updated.

Suppose you have an Employees table that may look as follows:

EmployeeId    Name       Address                ModificationDate
1             Spears     27 Sober Road 
2             Jagger     65 Straight Street 

If there is a real change in the value of any field except the EmployeeId and ModificationDate fields, the trigger should generate a time value and update the ModificationDate.

Example 1 of a real change:

update dbo.Employees
set Name = 'Beggar'
where EmployeeId = 2

Example 2 of no real change:

update dbo.Employees
set Name = 'Jagger'
where EmployeeId = 2

If an update in Example 2 executes, the trigger should not update the ModificationDate field.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:56:06+00:00Added an answer on May 24, 2026 at 12:56 am

    In a trigger, you have access to the ‘inserted’ and ‘deleted’ system tables.
    Those tables contains the records in the table that have been updated by the statement that caused the trigger to execute.

    For an ‘UPDATE’ trigger, the ‘inserted’ table contains the records like they are in the new state, the ‘deleted’ table contains the records with the old values.

    You’ll have to make use of those 2 tables to find out which records have really changed, and update the ModificationDate for those records.

    I think the statement inside the trigger will look something like this. (I haven’t tested it)

    UPDATE myTable
    SET ModificationDate = getdate()
    FROM inserted, deleted
    WHERE inserted.EmployeeId = deleted.EmployeeId
    AND (inserted.Name <> deleted.Name OR inserted.Address <> deleted.Address)
    

    Edit:
    I’ve played around a bit:

    create trigger upd_employee on [employee] after update
    as
    begin
    
        update employee
        set modifdate = getdate()   
        where employee.empid in 
        ( select i.empid
          from inserted i
          inner join deleted d on i.empid = d.empid 
          where (i.name <> d.name or i.address <> d.address )
        )
    end
    
    insert into employee 
    values
    (1, 'Frederik' , '', null)
    
    insert into employee
    values
    (2, 'User', '', null)
    
    update employee
    set [address] = 'some address'
    
    select * from employee
    
    update employee set [name] = 'test' where empid = 2
    
    select * from employee
    
    update employee set [name] = 'test' where empid = 2
    
    select * from employee
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a trigger that gets inserts and updates to a view. I need
I'm working with wordpress and need to create a trigger that updates a table
I need to write a trigger that rounds a value whenever it is inserted/updated
I have a table with two columns where I need one ( columnB )
Hi I need a trigger in sql server 2005 that will update a table
Suppose you have a trigger on MY_CUSTOMER_TABLE and that it has a variable declared
I need to create Trigger for delete action which backsup all fields old value
The table I am working with does not have a standard auto-increment field to
I need to create trigger in SQL Server 2008 that gone insert all values
Someone told me that I need to use a delimiter in my trigger. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.