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 8481139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:29:01+00:00 2026-06-10T19:29:01+00:00

I want to create a trigger to detect whether a row has been changed

  • 0

I want to create a trigger to detect whether a row has been changed in SQL Server. My current approach is to loop through each field, apply COLUMNS_UPDATED() to detect whether UPDATE has been called, then finally compare the values of this field for the same row (identified by PK) in inserted vs deleted.

I want to eliminate the looping from the procedure. Probably I can dump the content of inserted and deleted into one table, group on all columns, and pick up the rows with count=2. Those rows will count as unchanged.

The end goal is to create an audit trail:
1) Track user and timestamp
2) Track insert, delete and REAL changes

Any suggestion is appreciated.

  • 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-06-10T19:29:02+00:00Added an answer on June 10, 2026 at 7:29 pm

    Instead of looping you can use BINARY_CHECKSUM to compare entire rows between the inserted and deleted tables, and then act accordingly.

    Example

    Create table SomeTable(id int, value varchar(100))
    
    Create table SomeAudit(id int, Oldvalue varchar(100), NewValue varchar(100))
    
    
    Create trigger tr_SomTrigger  on SomeTable for Update 
    as
    begin
            insert into SomeAudit 
            (Id, OldValue, NewValue)
            select i.Id, d.Value, i.Value 
            from
            (
                Select Id, Value, Binary_CheckSum(*) Version from Inserted
            ) i
            inner join 
            (
                Select Id, Value, Binary_CheckSum(*) Version from Deleted
            ) d
            on i.Id = d.Id and i.Version <> d.Version
    
    
    End 
    
    Insert into sometable values (1, 'this')
    Update SomeTable set Value = 'That'
    Select * from SomeAudit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a trigger on a SQL Server table. Table has 8
I have a SQL Server 2008 database that has a Trigger. This trigger is
I work with SQL Server 2008 R2 I have a simple trigger CREATE TRIGGER
I use MS SQL 2008 and I want to create a trigger in a
I want to make a trigger in ms sql server which saves every insert,update
I want to create a trigger that runs just before a row in a
I want to create a trigger that execute on update of a table. in
I want to create trigger which will be fired after insert into some table,
I want to create a trigger, somehow like this: CREATE TRIGGER foo AFTER UPDATE
I have a strange problem here, I want to create an emtpy trigger: SET

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.