Thursday, July 3, 2014

Free Connections to a table before truncate

You don't really have a connection to a table, but processes take out locks on rows in the table as they access the rows. Or on table if they scan many rows.


It would be possible to query sys.dm_tran_locks to get the processes that hold locks, but you cannot really prevent new processes to come in.


A more lazy method is to issue your "TRUNCATE TABLE" in one query window, and then run sp_who in another. You process will be reported as blocked by other process, so you kill that process. Then you run sp_who again, kill that guy and so on.


Then again, killing processes in a production environment? It's not entirely appetising.





Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

No comments:

Post a Comment