Databases in SQL Server

There are basically the following two types of databases in SQL Server:
  1. System Databases.
  2. User Databases.

System Databases in SQL Server

System databases are databases that are created when SQL Server is installed. These databases are used for various operational and management activities for SQL Server.

Types of System Databases

There are basically four system databases in SQL Server, master, msdb, tempdb and model that we can see. Apart from that, there is one more system database resource database that is hidden and read-only. Let's move ahead with each system database.
System Database in SQL Server
Figure 1: System Database
System Database in SQL Server
Figure 2: System Database

Master Database in SQL Server

Assume the master database files are missing or inaccessible, will SQL Server start or up?

Answer: No, SQL Server will not start because the master database is the important database and all the configuration and information needed to start the SQL Server is stored in the master database itself hence without the master database SQL server will not start.
Query to see the physical file location of the master database:
  1. SELECT name, physical_name FROM sys.database_files;
Master Database in SQL Server
Figure 3: Master Database
For more information on the master database use the following link:
https://docs.microsoft.com/en-us/sql/relational-databases/databases/master-database?view=sql-server-2017

Model Database in SQL Server

  1. SELECT name, physical_name FROM sys.database_files;
Model Database in SQL Server
Figure 5: Data Table

A user has created a new database. What will be the recovery model of that database?

Answer: Because the model database acts as a template database, when a user creates a new database it will inherit the property of the model database and as we know by default the recovery model of the model database is FULL (until or unless the user changes it), hence the new database is created by the user with FULL RECOVERY MODEL.
For more information on the model database use the following link:
https://docs.microsoft.com/en-us/sql/relational-databases/databases/model-database?view=sql-server-2017

MSDB Database in SQL Server

  1. SELECT name, physical_name FROM sys.database_files;
MSDB database Table
Figure 6: MSDB database Table
For more information on the msdb database use the following link:
https://docs.microsoft.com/en-us/sql/relational-databases/databases/msdb-database?view=sql-server-2017

TempDB in SQL Server

  1. SELECT name, physical_name FROM sys.database_files;
TempDB Table in SQL Server
Figure 7: TempDB Table

Why we can't take a backup of a temp database?

Answer: Temp databases, as the name says, are used to do temporary operations, such as tables, Stored Procedures and cursors. Once the operation is over it will be cleared and is minimally logged. A TempDB is recreated everytime SQL is started, so it is always has a clean copy of the database hence backup and restore operations are not allowed for a TempDB.

How you will check to determine if the SQL Server is restarted?

Answer: Check the creation date of the tempdb, if it is new it means SQL Server is started.
SQL Server Database Properties
Figure 8: Database Properties
We can execute the following query also to check the tempdb creation date:
  1. select name, crdate from sys.sysdatabases;
tempdb creation date
Figure 9: Output
For more information on tempdb use the following link:
https://docs.microsoft.com/en-us/sql/relational-databases/databases/tempdb-database?view=sql-server-2017

Resource Database in SQL Server

Microsoft SQL System
Figure 10: Microsoft SQL System
We can see the location of the resource database file using the following query also:
  1. Use master GO
  2. SELECT
  3. 'ResourceDB' AS 'Database Name',
  4. NAME AS [Database File],
  5. FILENAME AS [Database File Location]
  6. FROM
  7. sys.sysaltfiles
  8. WHERE
  9. DBID = 32767 GO
For more information on the resource database use the following link:
https://blogs.msdn.microsoft.com/vsanil/2012/11/02/resource-database-common-questions/
What User Databases are: User databases are databases created by the user themself.
User Database
Figure 11: User Database
This is all about the SQL Server databases. I hope you liked it. To know more about SQL Server Database Administration click on below links :
Have a great day. Keep sharing your knowledge !!