When tried to empty one of the tempdb data file using the below T-SQL command:
(My goal here is to REMOVE the file using ALTER DATABASE command followed by. For more information on removing data/log files, please refer to this post How to Best Remove Extra TempDB Data Files and Log Files)
--To empty 'tempdev12' data file USE tempdb GO DBCC SHRINKFILE (tempdev12, EMPTYFILE); GO
I got the below error message:
DBCC SHRINKFILE: Page 9:44720 could not be moved because it is a work table page. Msg 2555, Level 16, State 1, Line 1 Cannot move all contents of file “tempdev12” to other places to complete the emptyfile operation. DBCC execution completed. If DBCC printed error messages, contact your system administrator.I figured out this is due to the existing connections and existing temp tables. To avoid this we can either
- Kill all the existing connections to the database OR
- Re-start the SQL Server
In may case it is not a critical production instance, so I just restarted the server and it worked.
For more information on how to use SHRINKFILE command please visit my previous post Transaction Log is Full – How to Shrink the Transaction Log


