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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:39:10+00:00 2026-06-05T09:39:10+00:00

I have a very suspicious feeling that this update trigger is updating ALL rows

  • 0

I have a very suspicious feeling that this update trigger is updating ALL rows on the target, not just those that satisfy the “update(shape)” test. Performance was fine ’till I added the second operation. A single spatial join occurs much faster, and this is a not a spatial index issue, as well, there are only a few records in this dataset.

ALTER TRIGGER   [dbo].[GRSM_WETLANDS_Point_GIS_tbl_locations_update]
ON  [dbo].[GRSM_WETLANDS_POINT]
after update  
AS   
BEGIN   
  SET NOCOUNT ON;  
  if UPDATE (shape)
update GRSM_WETLANDS_Point
set X_Coord =CASE WHEN u.shape.STDimension() = 2 THEN u.shape.STCentroid().STX ELSE u.shape.STEnvelope().STCentroid().STX END,
    Y_Coord =CASE WHEN u.shape.STDimension() = 2 THEN u.shape.STCentroid().STY ELSE u.shape.STEnvelope().STCentroid().STY END
    from inserted i 
inner join GRSM_WETLANDS_POint u on i.GIS_Location_ID = u.GIS_Location_ID;
--second spatial operation
update GRSM_WETLANDS_Point
set QuadName = grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES.name 

FROM GRSM_WETLANDS_POint i
inner join grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES  
on i.GIS_Location_ID = i.GIS_Location_ID  
WHERE  (USGS_24K_TOPOMAP_BOUNDARIES.Shape.STContains(i.SHAPE) = 1) ;

end

Is my suspicion right?

Upated: Based on suggestion from Aaron…solves the fire on all rows issue.

update GRSM_WETLANDS_Point
set QuadName = grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES.name 
FROM inserted i inner join GRSM_WETLANDS_POint u on i.GIS_Location_ID = u.GIS_Location_ID
left outer join  grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES  
on i.GIS_Location_ID = i.GIS_Location_ID  
WHERE  (USGS_24K_TOPOMAP_BOUNDARIES.Shape.STContains(i.SHAPE) = 1); 
  • 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-05T09:39:11+00:00Added an answer on June 5, 2026 at 9:39 am

    If Shape can’t be NULL, a better way to see if it has changed is to check if the values in inserted and deleted are different. For example:

    IF EXISTS
    (
      SELECT 1 FROM inserted AS i
      INNER JOIN deleted AS d
      ON i.GIS_Location_ID = d.GIS_Location_ID
      WHERE i.Shape.STEquals(d.Shape) = 0
    )
    BEGIN
      ...
    END
    

    If Shape is nullable then you just have to add more conditions there to check, e.g.

      WHERE 
      (
        (i.Shape IS NULL AND d.Shape IS NOT NULL
        OR (i.Shape IS NOT NULL AND d.Shape IS NULL)
        OR (i.Shape.STEquals(d.Shape) = 0)
      )
    

    (You might not care if Shape has been updated to NULL, I’m just illustrating how to test for that case.)

    Since the operation can occur on multiple rows, and this condition will only identify that at least one such update has occurred (but not that ALL rows meet the condition), it may be better to have your operations include similar criteria in the WHERE clause. In fact I think you can perform both updates in a single operation, e.g.

    ALTER TRIGGER [dbo].[GRSM_WETLANDS_Point_GIS_tbl_locations_update]
    ON  [dbo].[GRSM_WETLANDS_POINT]
    AFTER UPDATE
    AS   
    BEGIN   
      SET NOCOUNT ON; 
    
      UPDATE p SET 
        X_Coord = CASE WHEN i.shape.STDimension() = 2 
          THEN i.shape.STCentroid().STX 
          ELSE i.shape.STEnvelope().STCentroid().STX 
        END,
        Y_Coord = CASE WHEN i.shape.STDimension() = 2 
          THEN i.shape.STCentroid().STY 
          ELSE i.shape.STEnvelope().STCentroid().STY 
        END, 
        QuadName = COALESCE(b.name, p.QuadName)
      FROM 
        dbo.GRSM_WETLANDS_Point AS p
      INNER JOIN 
        inserted AS i
        ON i.GIS_Location_ID = p.GIS_Location_ID
      LEFT OUTER JOIN grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES AS b
        ON b.Shape.STContains(i.Shape) = 1
      WHERE EXISTS 
      (
        SELECT 1 FROM inserted AS i2
          INNER JOIN deleted AS d
          ON i2.GIS_Location_ID = d.GIS_Location_ID
          WHERE i2.GIS_Location_ID = i.GIS_Location_ID
          AND i2.Shape.STEquals(d.Shape) = 0
          -- ...and NULL handling if necessary
      );
    END
    GO
    

    In general, you seem to be having a lot of troubles implementing triggers, and make a lot of guesses about how the syntax should work. Have you considered forcing data updates to occur via stored procedures, where you can control all of this business logic but eliminate the complexity that the inserted and deleted pseudo tables add?

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

Sidebar

Related Questions

I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
I have very newbie question. How can i check that object of model is
I have very specific question, I cannot find a problem. I try update some
I have very obvious problem, but still did not found solution to it. I
I have very simple XML in a string that I'm trying to load via
I have very general problem on DNN 6.0 web site that I am working
I have very recently started development on a multiplayer browser game that will use
I have very simple query. I want to make sure that I don't have
I have very large Iterators that I want to split into pieces. I have
We have a C# service that has started failing in very odd ways around

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.