I know I’m missing something obvious here. This trigger is updating all rows in the table (killing performance) when all I want it to do is perform the update on the new inserted row.
CREATE TRIGGER [dbo].[update_location_topo_name]
--fires at each row insert, queries topo map layer (must be present!) and inserts name of topo into new location record
on [dbo].[TBL_LOCATIONS]
after insert
AS
BEGIN
update TBL_LOCATIONS
set TOPO_NAME = dbo.QD24K_GRSM.NAME
FROM dbo.tbl_locations
inner join dbo.QD24K_GRSM
on TBL_LOCATIONS.Location_ID = TBL_LOCATIONS.Location_ID
WHERE (QD24K_GRSM.Shape.STContains(TBL_LOCATIONS.SHAPE) = 1)
END
You need to reference the
INSERTEDpseudo table to get only the rows that were inserted.Additionally your join condition of
TBL_LOCATIONS.Location_ID = TBL_LOCATIONS.Location_IDmakes no sense at all.Probably better to do this as an
INSTEAD OFtrigger to modify the rows before insert rather than after they are inserted.