SQL Server TempDB Purpose and Importance of it
What is SQL Server TempDB and it's Purpose.
SQL Server TempDB is a system database that is automatically created whenever you install the SQL Server on a machine and also it creates each time when you start the SQL Service.
The Purpose of the SQL Server TempDB is, it used by the SQL Server and the database users for sorting operations and it's used to create Global or Local temporary tables, and Temporary stored procedures.
Additionally, the TempDB can also be used to offload sorting from main database to TempDB while index creation using SORT_IN_TEMPDB to improve the performance.
Important points to be remembered for TempDB:
- you can't drop it like normal database
- You can't back up and restore
- You can't change it's recovery model
- You can't create multiple file groups
- You can't detach it like normal database
Best practices about TempDB configuration:
- Should always keep both the datafile and logfile on a separate disk
- Always place the files on the faster IO subsystem
- It's important to pre-size auto growth both datafile and logfile
- If you create multiple datafile for tempdb, so make sure to keep the equal sizes of files
Commands:
Check the tempdb datafile location:
sp_helpdb tempdb
Move the temp files to another location:
ALTER DATABASE tempdb
MODIFY FILE
(NAME = tempdat, FILENAME = 'D:\TEMPDATABASE\tempdb.mdf'); ---- new location
GO
ALTER DATABASE tempdb
MODIFY FILE
(NAME = templog, FILENAME = 'D:\TEMPDATABASE\templog.ldf'); ---- new location
GO
Comments
Post a Comment