SQL Server System Databases
Master:Records all the system-level information for an instance of SQL Server.
Msdb: Is used by SQL Server Agent for scheduling alerts and jobs.
Model: Is used as the template for all databases created on the instance of SQL Server. Modifications made to the model database, such as database size, collation, recovery model, and other database options, are applied to any databases created afterward.
Resource: Is a read-only database that contains system objects that are included with SQL Server. System objects are physically persisted in the Resource database, but they logically appear in the sys schema of every database.
Tempdb: Is a workspace for holding temporary objects or intermediate result sets.
Every instance of SQL Server has a single TempDB system database which is shared by all other databases on the same instance. Since SQL Server 2005, TempDB has been used more and more with every new SQL Version.
TempDB is used for the following purpose:
- User Objects:
- Local and Global Temporary Tables and their indexes
- Table Variables
- Temp Procedures
- Internal Objects:
- Work tables for Hash operations and aggregates
- Work tables for DBCC CHECKDB and DBCC CHECKTABLE
- Work files needed for SORT, GROUP BY, ORDER BY, UNION operations
- CTEs: Common Table Expressions
- Storing Temporary LOB storage: If they won’t fit in Memory
- Work tables for processing Service Broker objects
- Version Store:
- Online Index Operations
- MARS- (Multiple Active Result Sets)
- Snapshot Isolation
- Read Committed Snapshot Isolation
Few important restrictions we have on TempDB:
- Cannot remove PRIMARY data file or log file
- Cannot rename or drop TempDB database
- Cannot make the TempDB OFFLINE
- Cannot add, remove or rename FILEGROUP
- Cannot change the Collation , default is Server Collation
- Cannot change the owner of the TempDB, its owner is always dbo.
- Cannot BACKUP or RESTORE TempDB