SQL Server System Databases — Basic Concepts

Image for post
Image for post

Introduction

Overview of System Databases

-- Listing 1: System Databases
select
name
,database_id
,create_date
,state_desc
,recovery_model_desc
,log_reuse_wait_desc
,physical_database_name
,is_db_chaining_on
,is_broker_enabled
,is_mixed_page_allocation_on
from sys.databases
where database_id<5;
-- Listing 2: System Database Files
select
name
,database_id
,DB_NAME(database_id)
,name
,physical_name
,type_desc
from sys.master_files
where database_id<5;
Image for post
Image for post
Figure 1: System Databases

The master Database

Image for post
Image for post
Image for post
Image for post
Figure 3: SQL Server Startup Parameters
Image for post
Image for post
Figure 4: Navigating Master Database Objects

The tempDB Database

The model Database

-- Listing 3: Using the Model Database
select
name
,database_id
,DB_NAME(database_id) database_name
,name
,physical_name
,type_desc
,size/1024*8 [size (MB)]
,growth/1024*8 [size (MB)]
from sys.master_files
where DB_NAME(database_id)='model' or DB_NAME(database_id) like 'EXP%';
GO
create database EXP_BEFORE;
GO
USE [master]
GO
ALTER DATABASE [model] MODIFY FILE ( NAME = N'modeldev', SIZE = 102400KB , FILEGROWTH = 131072KB )
GO
ALTER DATABASE [model] MODIFY FILE ( NAME = N'modellog', SIZE = 102400KB )
GO
create database EXP_AFTER;
GO
select
name
,database_id
,DB_NAME(database_id) database_name
,name
,physical_name
,type_desc
,size/1024*8 [size (MB)]
,growth/1024*8 [size (MB)]
from sys.master_files
where DB_NAME(database_id)='model' or DB_NAME(database_id) like 'EXP%';
GO
Image for post
Image for post

The msdb Database

-- Listing 4: Querying msdb Objects-- Jobs, Alerts, Operators sit in the msdb database ...
select * from msdb..sysjobs
select * from msdb..sysalerts
select * from msdb..sysoperators
select * from msdb..sysmail_allitems
-- ... NOT in the master database
select * from master..sysjobs
select * from master..sysalerts
select * from master..sysoperators
select * from master..sysmail_allitems

Epilogue

Written by

Awesome blog focused on databases and Microsoft, .NET and cloud technologies. http://codingsight.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store