I know row-by-row isn't the best, but this is a process that I inherited that I cannot change in the near-term.
The process itself is such: when picking an order, for each item in the order, the warehouse location to be used is determined based on some business rules, a call is made to the (separate) warehouse database to move the product from the location, a record is placed in my local table indicating from where the product is to be physically picked (later used to create a pick list). We could look to store what would be the local table entries in a temp table, then push them all in at once--but that only helps our automated picking process. Sometimes a user must manually select the locations to be used for each line of the order--once they've made their choices, a VB-loop calls the same SP the automated loop calls to perform the WHMS move and record the record in our table.
As for the contents of the trigger: (some names changed to protect the innocent)
Code:
ALTER TRIGGER T_Order_Picked_Items_Insert ON dbo.Order_Picked_Items
FOR INSERT
AS
INSERT
INTO AuditDB.dbo.Order_Picked_Items
(_fields_, A_Date, A_User, A_Machine)
SELECT _fields_, GETDATE(), USER_NAME(), HOST_NAME()
FROM inserted
GO
Nothing fancy. the table contains about a dozen fields--most are either Int or Varchar fields (no blobs, nothing larger than vc-255), with one decimal (19, 9), one date/time and one bit field. Primary key (on the main table) is three int fields (site, order, sequence number). The destination is a heap with no indexes or keys.
This exact same trigger logic is used in the Insert-triggers of every table in the database (including the order-items table which has the same level of activity but superior performance). Only this table has the performance problems we are experiencing...
The WHMS has similar triggers as well for their auditing--and according to the Execution Plan in QA, their Location-table update trigger has a sub-tree cost of ~1.22, while my insert trigger has a sub-tree cost of 33.9 (the actual insert into the audit table is only 0.0108--the inserted scan is costing 33.85, so I know it isn't the destination data table since that is almost no-cost)!
We've checked the integrity of the database--no errors. Could indexing have an adverse affect on the FOR INSERT trigger? That's my only suspicion at this point, seeing how long that inserted scan portion of the trigger is taking.
Thanks in advance for any help.