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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:55:51+00:00 2026-05-27T13:55:51+00:00

There is a certain job that will insert and update this table called ContactInfo

  • 0

There is a certain job that will insert and update this table called ContactInfo (with 2 columns – Id, EmailId) several times a day.

What’s a good way to write a trigger on this table to revert back the EmailId for only specific Ids, whenever only those EmailIds for those Ids get updated?

Don’t mind hard-coding those Ids in the trigger since the list is about 40.

But specifically concerned about trigger not firing for every update, since updates happen all the time, and don’t want the trigger to cause resource issues.

Additional info: table has about 600k entries and is indexed on Id.

In summary: is it possible for the trigger to get fired only when certain values are updated in the column, and not any update on the column.

  • 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-27T13:55:52+00:00Added an answer on May 27, 2026 at 1:55 pm

    One alternative mechanism you might consider would be adding another table, called, say, LockedValues. I’m a bit unsure from your narrative what values you’re trying to prevent changes to, but here’s an example:

    Table T, contains two columns, ID and Val:

    create table T (
        ID int not null,
        Val int not null,
        constraint PK_T PRIMARY KEY (ID),
        constraint UK_T_Lockable UNIQUE (ID,Val)
    )
    

    And we have 3 rows:

    insert into T(ID,Val)
    select 1,10 union all
    select 2,20 union all
    select 3,30
    

    And we want to prevent the row with ID 2 from having it’s Val changed:

    create table Locked_T (
        ID int not null,
        Val int not null,
        constraint UQ_Locked_T UNIQUE (ID,Val), --Only really need an index here
        constraint FK_Locked_T_T FOREIGN KEY (ID,Val) references T (ID,Val)
    )
    insert into Locked_T (ID,Val) select 2,20
    

    And so now, of course, any application that is only aware of T will be unable to edit the row with ID 2, but can freely alter rows 1 and 3.

    This has the benefit that the enforcement code is built into SQL Server already, so probably quite efficient. You don’t need a unique key on Locked_T, but it should be indexed so that it’s quite quick to detect that values aren’t present.

    This all assumes that you were going to write a trigger that rejected changes, rather than one that reverted changes. For that, you’d still have to write a trigger (though I’d still suggest having this separate table, and then writing your trigger to do an update inner joining inserted with Locked_T – which should be quite efficient still).

    (Be warned, however: Triggers that revert changes are evil)

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

Sidebar

Related Questions

For example, are there certain things when writing an operating system that cannot be
There are certain conditions that can cause stack overflows on an x86 Linux system:
In various projects there are certain parts I will keep jumping to. Is there
When building ASP.NET projects there is a certain amount of boilerplate, or plumbing that
I've had a good look around and am certain that there's no matching question
There are times when I want to use mootools for certain things and Prototype
I want a method to update certain entries of an IEnumerable. I found that
I have a job that performs several validation checks on rows in several tables
I am installing a WPF Application using the ClickOnce deployment. There are certain settings
There's a loop where we get certain data. Depending on the data, file writer

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.