Published on

April 29, 2023

Understanding SQL Server Tempdb Database

The tempdb database is an essential component of SQL Server. However, there are several misconceptions and myths surrounding this database. In this article, we will debunk these myths and provide you with five important facts about tempdb.

Fact 1 – SQL Server Instance Start Date and Time

When a SQL Server instance is started, a new tempdb database is created. This means that the instance start date and time are the same as the tempdb creation date and time. By checking the tempdb database creation date, you can determine when the instance was last started. This information can be easily accessed in SQL Server Management Studio (SSMS) by right-clicking on tempdb and selecting “Properties”. In the “General” tab, you will find the “Date Created” field, which indicates the tempdb database creation date.

Fact 2 – Temporary Tables and Stored Procedures

Contrary to popular belief, temporary tables and temporary stored procedures are stored in the tempdb database, not in memory (RAM). You can verify this by creating temporary tables and stored procedures and then locating them in tempdb using SSMS. Temporary tables can be found under “Temporary Tables” and temporary stored procedures under “Programmability” > “Stored Procedures”. This visual proof confirms that these objects physically exist in the tempdb database.

Fact 3 – Regular Tables in Tempdb

It is possible to create regular tables in tempdb. These tables are different from temporary tables as they are available from other sessions and are not automatically deleted even if there are no connections to them. However, it’s important to note that these regular tables are not permanent. After restarting the SQL Server instance, a new copy of tempdb is created, and all user-created objects, including regular tables, are deleted.

Fact 4 – Backup and Restore of Tempdb

The tempdb database is not intended for storing permanent information, and therefore, it cannot be backed up or restored. Unlike other databases, there is no “Back Up…” option available for tempdb in SSMS. If you attempt to back up tempdb using T-SQL code, you will receive an error message indicating that it is not allowed. This is because tempdb is designed to be recreated every time the SQL Server instance starts.

Fact 5 – Row Versioning and Tempdb

When row versioning is enabled in SQL Server, the row versions are stored in tempdb. This is true for both the READ COMMITTED and SNAPSHOT isolation levels. In these isolation levels, the initial versions of rows are stored in tempdb to support concurrency and provide access to the original data from snapshots. However, it’s important to consider that storing row versions in tempdb can potentially overload the database.

Conclusion

Understanding the facts about the tempdb database is crucial for efficient SQL Server administration. By dispelling common myths and misconceptions, you can make informed decisions and optimize your database performance. Remember that tempdb is a dynamic and essential component of SQL Server, and being aware of its functionalities will greatly benefit your database management.

Article Last Updated: 2021-03-02

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.