Link to home
Create AccountLog in
Microsoft SQL Server

Microsoft SQL Server

--

Questions

--

Followers

Top Experts

Avatar of HubertFarnsworth
HubertFarnsworth🇺🇸

Can SQL Server Update Trigger Silently Reject a Single Column Value?
Good Day!

I need to change an update trigger in SQL Server 2008 to silently reject any attempts to change a single column value. The user may issue UPDATE statements which are updating numerous columns. I need to stop them from changing one column in particular, but I do not want to raise an error.

I tried using the deleted table to restore the original column value, but I cannot get it to work. Chances are I'd get a dangerous loop going, anyway. I also considered an INSTEAD OF trigger, but I'd that to be my last resort.

So, imagine I have this table:

TableA
ColumnUID   INTEGER PK
ColumnA     CHAR(10)
ColumnB    CHAR(100)

The user may issue this statement:
UPDATE TableA
SET ColumnA = 'ABC'
, ColumnB = 'Winter Park'
WHERE ColumnUID = 123;

I want the trigger to allow the ColumnB change to occur, but reject the change on ColumnA. It needs to be silent.

IF UPDATE(ColumnA)
BEGIN
    << Do not actually change ColumnA >>
END

Any assistance would be appreciated.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Anthony PerkinsAnthony Perkins🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of HubertFarnsworthHubertFarnsworth🇺🇸

ASKER

It worked beautifully! Thanks!!!

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft SQL Server

Microsoft SQL Server

--

Questions

--

Followers

Top Experts

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.