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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:37:46+00:00 2026-05-14T02:37:46+00:00

I have a stored procedure that says update table1 set value1 = 1 where

  • 0

I have a stored procedure that says

update table1 set value1 = 1 where value1 = 0 and date < getdate() 

I have a trigger that goes like

CREATE TRIGGER NAME ON TABLENAME
FOR UPDATE
...
if UPDATE(value1) 
BEGIN
--Some code to figure out that this trigger has been called
-- the value is always null
END

Any idea why this trigger is called even when the stored procedure does not update any values?

  • 1 1 Answer
  • 1 View
  • 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-14T02:37:46+00:00Added an answer on May 14, 2026 at 2:37 am

    Read the books online article about update(), it’s actually a good read.
    You can find it here, http://msdn.microsoft.com/en-us/library/ms187326.aspx.

    To answer:
    Update() will return true if the column is “updated,” even if no rows were affected by the update.

    For example (setup):

    If OBJECT_ID('TestTrigger', 'U') is not null drop table TestTrigger
    GO
    create table TestTrigger(
      ID int identity(1,1)
    , Col1 int
    , Col2 int
    , Trig varchar(1) default 'N' 
    )
    Insert into TestTrigger(Col1, Col2) values (1,1)
    Insert into TestTrigger(Col1, Col2) values (1,2)
    GO
    IF OBJECT_ID('Testing', 'TR') is not null drop trigger Testing
    GO
    Create Trigger Testing on TestTrigger
    For Update
    as
    Begin
    If Update(Col1)
        begin
            Update TestTrigger Set Trig='Y' where ID=(Select ID from Inserted)
        end
    End 
    

    If I run Update TestTrigger Set Col1=0 where Col2=1 and check my rows affected I’ll see

    (1 row(s) affected)
    (1 row(s) affected)
    

    Which we know is true, 1 is affected by the update statement, the other by the trigger.
    If I run Update TestTrigger Set Col1=0 where Col2=10 I’ll see,

    (0 row(s) affected)
    (0 row(s) affected)
    

    This means that Update(Col1) is returning as true (because otherwise we’d only get a single rows affected returned).

    If I run Update TestTrigger Set Col2=0 where Col2=10 I’ll see

    (0 row(s) affected)
    

    This is because Col1 is no longer referenced. As @Schar mentioned checking @@RowCount is a good idea as well, or alternatively you could use something like I did (linking inserted).

    Kris

    EDIT: and to add, from the Create Trigger BO article (http://msdn.microsoft.com/en-us/library/ms189799.aspx),

    These triggers fire when any valid
    event is fired, regardless of whether
    or not any table rows are affected.

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

Sidebar

Related Questions

I have a stored procedure that looks like: CREATE PROCEDURE dbo.usp_TestFilter @AdditionalFilter BIT =
I have a stored procedure that returns data in the format of: Date |
I have a stored procedure that has this line: SET @SQL = 'SELECT path,title,tags
I have a stored procedure that returns multiple resultsets just as below CREATE StoredProcedure
Everything I have read says that when making a managed stored procedure, to right
I have a stored procedure that has the parameter: @desk VARCHAR(50) I want to
I have this stored procedure that I want to use for my SAP crystal
I have a stored procedure (that I didn't write) that uses openquery to populate
I have a stored procedure that takes a user ID and calculates their balance
I have a stored procedure that takes no parameters, and it returns two fields.

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.