Wednesday, May 10, 2017

The TempDB System Database in SQL Server

This article is from my book:
Tuning SQL Server (eBook)

Tuning SQL Server (Second Edition)

Table of Contents | Sample ChapterLearn More

The tempdb system database in SQL Server is one of the databases that are shipped with every SQL Server installation and it is used for specific tasks as a temporary storage. Examples of when tempdb is used are:
  • Use of local/global temporary tables, stored procedures and variables.
  • Use of cursors.
  • When the SORT_IN_TEMPDB option is used during the creation or rebuild of indexes.
  • Use of local/global stored procedures.
  • When row versions are generated by different transactions.

TempDB is protected with the use of certain built-in restrictions in SQL Server. These are:
  • You cannot drop it.
  • You cannot back it up/restore it.
  • You cannot change the database owner (it is always the dbo).
  • You cannot create a database snapshot.
  • You cannot drop the guest user.
  • You cannot add filegroups.
  • You cannot change the collation (default collation is server’s collation).
  • You cannot take the database offline.
  • You cannot set the database or primary filegroup to READ_ONLY.
  • You cannot rename the database or its primary filegroup.
  • You cannot remove the primary filegroup, data or log file.
  • TempDB cannot participate in database mirroring.
  • You cannot enable change data capture on TempDB.

TempDB is heavily used in a variety of SQL Server operations and contributes a lot to performance of database operations. To this end, you need to maintain the good health of TempDB in order to contribute towards a performant SQL Server instance. For example, you must ensure that there is an adequate amount of available free disk space as TempDB expands when used. Also, using multiple data files can help applying parallelism in TempDB database.

Learn more about SQL Server Performance Tuning in my latest eBook "Tuning SQL Server (second edition)"!

The SQL Server and .NET Hub

Reference: The SQL Server and .NET Hub (

What are your views on the subject? Have something to share? Feel free to leave your comment!

Check out my latest eBook on SQL Server:
Tuning SQL Server - Ebook

Easily secure your SQL Server instances! Try out DBA Security Advisor!
DBA Security Advisor for SQL Server by SQLArtBits
DBA Security Advisor was developed by SQLArtBits. The tool was being carefully developed for an entire year and it contains comprehensive security checks and recommendations based on proven SQL Server security best practices. Feel free to download and use the Community Edition which is free and if you find it useful, you can consider upgrading to the Enterprise Edition!

Artemakis Artemiou [MVP]

Author & Editor

Artemakis Artemiou is a Senior SQL Server Architect, Software Developer and Microsoft Data Platform MVP. He is also an author, regular blogger, president of Cyprus.NET User Group and CY Country leader of INETA-EU. He is also the creator of DBA Security Advisor and In-Memory OLTP Simulator. Artemakis is a frequent guest author of worldwide well-respected online journals where he writes articles focusing on many SQL Server topics.

Reference: The SQL Server and .NET Hub (