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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:18:09+00:00 2026-06-03T15:18:09+00:00

I have a trigger which is as follows: ALTER TRIGGER [trigger_CATEGORY_VALUE_ID] ON [dbo].[tblA] FOR

  • 0

I have a trigger which is as follows:

  ALTER TRIGGER [trigger_CATEGORY_VALUE_ID] ON [dbo].[tblA]
FOR UPDATE
AS
SET NOCOUNT ON
IF ( UPDATE([CATEGORY_VALUE_ID]))
BEGIN
  INSERT INTO [dbo].[htblB]
  ( ID
  , CATEGORY_VALUE_ID
  , STATUS_END_DATE
  , STATUS_END_DATE_SOURCE)
  SELECT
  t.ID
  , t.CATEGORY_VALUE_ID
  , GETDATE()
  , t.UPDATE_SOURCE
  FROM [dbo].[tblCAPITATION] t
  INNER JOIN inserted ins
  ON t.CATEGORY_VALUE_ID = ins.CATEGORY_VALUE_ID 
END

What it needs to do is insert a new row in htblB when the column CATEGORY_VALUE_ID is updated. It works fine if only one row is updated. But if it has multiple row updates, then 2 to the power number of rows updated amount of new rows are inserted in htblB.

UPDATE dbo.tblCAPITATION
SET CAPITATION_STATUS_CATEGORY_VALUE_ID = '80574', UPDATE_SOURCE = 'TEST3'
WHERE CAPITATION_ID = 2 OR CAPITATION_ID = 3

This statement will insert 4 new rows to htblB instead of 2.

May you please shed some light on why this is hapening and how to prevent it?

Thanks!

  • 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-03T15:18:12+00:00Added an answer on June 3, 2026 at 3:18 pm

    I’m going to assume that ID is the primary key, if so then you should be joining inserted on ID not category_value_id

    ALTER TRIGGER [trigger_CATEGORY_VALUE_ID] ON [dbo].[tblA]
    FOR UPDATE
    AS
    SET NOCOUNT ON
    IF ( UPDATE([CATEGORY_VALUE_ID]))
    BEGIN
      INSERT INTO [dbo].[htblB]
      ( ID
      , CATEGORY_VALUE_ID
      , STATUS_END_DATE
      , STATUS_END_DATE_SOURCE)
      SELECT
      t.ID
      , t.CATEGORY_VALUE_ID
      , GETDATE()
      , t.UPDATE_SOURCE
      FROM [dbo].[tblCAPITATION] t
      INNER JOIN inserted ins
      ON t.ID = ins.ID
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below trigger ALTER TRIGGER [dbo].[DeleteUserData] ON [dbo].[site_users] AFTER DELETE AS BEGIN SET
I have a stored procedure which is called inside a trigger on Insert/Update/Delete. The
I have a trigger for insert/update/delete. That is working fine. Also, I need the
I have written an update trigger which works fine when i update only one
Once again.. i have the trigger below which has the function to keep/set the
I have a trigger which executes after a record is inserted into a table.
I have this trigger which works functionally (as far as I can tell by
I have within my Sql Server 2008 database a trigger which will run on
I have an Activity in which user can update a specific information clicking in
I have written an application which triggers an IP Camera to stream it's data

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.