Home Forums SQL Server 7,2000 T-SQL stored procedure vs individual insert statements RE: stored procedure vs individual insert statements

  • Is it a typo, or are you really intending on selecting the same table into itself?

    I've noticed this on occasion as well (something runs well/as expected in query analyzer, but the moment it is a procedure, performance plummets). Perhaps greater SQL minds than mine have some insight into this problem. These are just my random musings, but I wonder if it has something to do with transaction management/locking and latching. I wonder if wrapping each statement in a begin tran/commit block would help, since it would force out writes to the transaction log.

    The other thing is if you are really selecting the same table into itself, depending on its size, consider copying out the records to a temp table, and copying them back in to prevent contention or latching or locking to the table. SQL Gurus, please step in if I've misstated something here, because this area has always been somewhat of a mystery to me.

    Hope this at least sparks some interesting thought.

    Thanks!