Temp Tables in a Trigger

  • Hi,

    I have been told it's bad to use temp tables in a trigger but not given much of an explanation. Let's say the insert (or update) trigger almost only ever gets called when multiple records are being inserted (or updated), and the trigger logic requires many data queries on very large tables and some calculations. Is it still bad?

  • Any form of heavy processing in a trigger is bad. Triggers should be fast and lightweight as they are called any time a row changes and any locks taken by the operation that fired the trigger are held until the end of the trigger.

    Heavy processing in a trigger can easily cause blocking, deadlocks and query timeouts.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply