tempdb shrinking and emptying datafiles

  • Hi I found some script online to emptyfile and shrink data files for tempdb.

    We have 10 data files and we dont need 10 files now.

    USE tempdb
    GO
    DBCC SHRINKFILE (tempdb3, EMPTYFILE); -- to empty " data file
    GO

    ALTER DATABASE tempdb
    REMOVE FILE tempdb3; --to delete  data file
    GO

    What happens to the temp tables etc created in those files, and will emptying and deleting extra data files cause any data loss?

  • If you use EMPTYFILE, any data gets moved to the other data files in the same filegroup and nothing else will get added to the file. So there is no data loss.
    Nonetheless, you should do it during a maintenance window, scheduled downtime or whatever you have along those lines.

    Sue

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

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