Temp tables in SQL Server 2005 not automatically dropped

前端 未结 2 1189
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 12:23

I\'m troubleshooting a nasty stored procedure and noticed that after running it, and I have closed my session, lots of temp tables are still left in tempdb. They have names

相关标签:
2条回答
  • 2021-01-15 12:41

    http://www.sqlservercentral.com/Forums/Topic456599-149-1.aspx

    If temp tables or table variables are frequently used then, instead of dropping them, SQL just 'truncates' them, leaving the definition. It saves the effort of recreating the table next time it's needed.

    0 讨论(0)
  • 2021-01-15 12:54

    Tables created with the # prefix are only available to the current connection. Therefore any new connection you create will not be able to see them and therefore not be able to drop them.

    How can you tell that they still exist? What command are you running to find this out?

    Is the connection that created them closed properly? If not then this may be why they still exist.

    0 讨论(0)
提交回复
热议问题