[Quick Tip] When is TempDB Used?

[Quick Tip] When is TempDB Used?

[Quick Tip] When is TempDB Used?

When is TempDB Used? That’s a very good question!

TempDB is one of the system databases of SQL Server. As its name implies, it is being used for holding temporary stuff. However, after different discussions I had with a lot of people, I believe that many people have a misconception regarding when TempDB is actually used in SQL Server, and consequently, they might not be taking into full consideration the performance-related factors and guidelines about this special database.

So the question remains: When is TempDB Used? 

TempDB is not just used for storing temporary tables. Besides from storing user objects (global/local temporary tables and indexes, temporary stored procedures, table variables, Tables returned in table-valued functions, or cursors), the TempDB database is also used for storing internal objects which are created by the Database Engine such as:
– Work tables that are used for storing intermmediate results.
– Work files for hash join or hash aggregate operations.

– Intermmediate sort results of operations such as index rebuild, etc.

Moreover, tempdb is used to store version stores, that is collection of data pages that contain data which is used by operations that utilize row versioning.

For all the above reasons, you need to take into consideration the performance optimization guidelines regarding the TempDB database, as it plays a significant role to the overall performance of your SQL Server instance.

I have written another more comprehensive article in the past, dedicated to the TempDB system database in SQL Server. Feel free to check it out here.

Moreover, feel free to check out my eBook “Tuning SQL Server” where I dedicated a full chapter on the TempDB database.


Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)


Reference: SQLNetHub (https://www.sqlnethub.com)

© SQLNetHub




Artemakis Artemiou
Artemakis Artemiou is a Senior SQL Server and Software Architect, Author, and a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Artemakis's official website can be found at aartemiou.com.