I have a store procedure that inserts records in table and at the same time delete all records older then 20 minutes.
I have try to optimized it and have seen that the delete operation cost to much. So, I have decided to create after insert trigger that do the delete operation.
It seems, that it works faster now, but the execution plan is showing the “delete” statement from the trigger – the only difference is that now the delete statement has “Query Cost (relative to the batch): 0%.”
My question is, when the procedure inserts the records, will it immediately returns the results or it will wait for the after insert trigger to complete?
The trigger is part of the same transaction as the calling procedure, so the whole transaction will only complete once the trigger has fired, from MSDN:
MSDN – Understanding DML Triggers