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

  • Home
  • SEARCH
  • 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 7725261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:53:39+00:00 2026-06-01T04:53:39+00:00

I am writing an instead of trigger for updates that does some auditing and

  • 0

I am writing an instead of trigger for updates that does some auditing and then should only perform the actual update when any column changes, except two. I have a query that does this, but the problem is maintenance. The query has to list out every column in the table several times and this table (and several others like it) are likely to change. This puts a very large burden on the programmer every time any changes are made. Here is what the query looks like:

create trigger member_history_trigger on Member
instead of update
as
begin

insert into MemberHistory (Name, Address, RevisedBy, RevisedDate)
select d.Name, d.Address, d.RevisedBy, d.RevisedDate
from DELETED d 
join INSERTED i on (d.memberid = i.memberid)
where (d.Name != i.Name or d.Address != i.Address);


update m
set   m.Name = i.Name
    , m.Address = i.Address
    , m.RevisedBy = i.RevisedBy
    , m.RevisedDate = i.RevisedDate
from INSERTED i left join Member m on (i.MemberID = m.MemberID)
where (m.Name != i.Name or m.Address != i.Address)

end

As you can see above, I only want to perform an update when a field other than RevisedBy or RevisedOn changes. This example looks simple, but in reality this table has 20 fields and there are 10 other tables like it for which this same thing must be done.

Can I do this same thing, but without listing out the names of each column? Is there a way to say, “Update every column if any column has changed other than RevisedBy or RevisedDate?” If there is, I would never have to look at these queries ever again.

  • 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-01T04:53:40+00:00Added an answer on June 1, 2026 at 4:53 am

    Nope.

    As a rule, it’s difficult to indicate fields without being explicit for very good reasons, such as the ability (and frequent occurence of) table structure changes.

    I’m not aware of any method for specifying a subset of columns without using either dynamic SQL (dangerous, and downright terrifying inside a trigger) or explicitly listing them out.

    It’s a pain, but it’s a proper practice and will prevent all sorts of unexpected consequences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: i just realized that, how about dont allow any special characters instead of
A friend of mine is programming a web page. Instead of writing any HTML
In a Silverlight application, instead of consuming and writing (wcf) wrappers around messages that
So instead of writing a looping function where you instantiate an array and then
Instead of writing the SQL query, is there any lazy way to get the
Some C compilers permit multiple characters in a character constant. This means that writing
I'm currently writing a custom component in Java that instead of writing a static
I modify the OpenRtspClient so that Now instead of writing frames to file I
I'm just getting started on writing functions instead of writing everything inline. Is this
Instead of writing too many sql statements in each servlet I just want to

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.