0% found this document useful (0 votes)
61 views

Database in SQL Server 2022

The document discusses databases in SQL Server. It describes the different types of databases including system databases like master, msdb, model and tempdb. It also talks about user databases. It then explains concepts like database architecture including logical and physical components, database files, filegroups, extents and pages.

Uploaded by

Mykaa Dba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Database in SQL Server 2022

The document discusses databases in SQL Server. It describes the different types of databases including system databases like master, msdb, model and tempdb. It also talks about user databases. It then explains concepts like database architecture including logical and physical components, database files, filegroups, extents and pages.

Uploaded by

Mykaa Dba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Database in SQL Server

In this Chapter, Lets we discuss important concept called Databases.

Here we have different types of Databases Available.

What you will learn:

1. Database Architecture
2. System Databases
3. Data Files
4. Log Files
5. Extents
6. Pages

Work with databases use the SQL Server Management Studio tool.

The Management Studio tool has a graphical user interface for creating
databases and the objects in the databases.

System Databases:

When we install MS SQL Server on our system, the system databases are created
automatically. It plays an important role for the server to function properly.
Mayukha IT Services
[email protected]
+91-9573349020
https://realtimedba.thinkific.com/courses/your-first-course\
https://www.linkedin.com/in/mayukhaitservices/
The following is a list of SQL Server's system databases:

1. Master,
2. Model,
3. MSDB,
4. Tempdb,
5. Resource DB(Hidden state) –Files Server in default

Files will be available in below Location


C:\Program Files\Microsoft SQL
Server\MSSQL16.MSSQLSERVER\MSSQL\Template Data\

File Names should be

Mssqlsystemresource.mdf
Mssqlsystemresource.ldf

These Databases consist of the meta data.

User Databases:

These databases are created by database users like DBAs and testers who can
also access and manipulate their data.

SQL Server provides two ways to list all or specific databases:

Mayukha IT Services
[email protected]
+91-9573349020
https://realtimedba.thinkific.com/courses/your-first-course\
https://www.linkedin.com/in/mayukhaitservices/
o Transact-SQL Command
o SQL Server Management Studio (SSMS)

o Transact-SQL Command

master Records all the system-level information for an instance of SQL Server.
Database
msdb Is used by SQL Server Agent for scheduling alerts and jobs.
Database
model Is used as the template for all databases created on the instance of SQL Server.
Database 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
Database 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.
Database

Database Architecture

SQL database is divided into logical and physical components.

Mayukha IT Services
[email protected]
+91-9573349020
https://realtimedba.thinkific.com/courses/your-first-course\
https://www.linkedin.com/in/mayukhaitservices/
Logical Component
Logical components comprises of following:
Database objects,
Collation,
Login, Users, Roles and groups.

Physical component
Physically components exist as two or more files on disk.
Physically files can be of three types.

Primary data files


This is starting point of the database and contain pointer to point other files.
Extension is mainly .mdf .

Secondary data files


It consists of data other than primary data file. Extension is mainly .ndf .

Log files
It contains log information which is used to recover database.

What are database files and filegroups?

Database files are used for mapping the database over some operating system
files. Data and log information are separate.

SQL server database has three types of database files:


Primary: starting point of a database. It also points to other files in database.
Extension: .mdf

Mayukha IT Services
[email protected]
+91-9573349020
https://realtimedba.thinkific.com/courses/your-first-course\
https://www.linkedin.com/in/mayukhaitservices/
Secondary: All data files except primary data file is a part of secondary files.
Extension: .ndf
Log files: All log information used to recover database. Extension: .ldf

File Groups
Database files can be grouped together in file groups for allocation and
administration purposes. No file can be a member of more than one file group.
Log files are never part of a file group. Log space is managed separately from data
space.

There are two types of file groups in SQL Server, Primary and User-defined.
Primary file group contains the primary data file and any other files not
specifically assigned to another file group. All pages for the system tables are
allocated in the primary file group

Extents
Extents are basic unit in which space is allocated to tables and indexes. An extent
is 8 contiguous pages or 64KB. SQL Server has two types of extents - Uniform and
Mixed. Uniform extents are made up of only single object. Mixed extents are shared
by up to eight objects.
Pages
It is the fundamental unit of data storage in MS SQL Server. The size of the page is
8KB. The start of each page is 96 byte header used to store system information

Mayukha IT Services
[email protected]
+91-9573349020
https://realtimedba.thinkific.com/courses/your-first-course\
https://www.linkedin.com/in/mayukhaitservices/
such as type of page, amount of free space on the page and object id of the object
owning the page. There are 9 types of data pages in SQL Server.
 Data − Data rows with all data except text, ntext and image data.
 Index − Index entries.
 Tex\Image − Text, image and ntext data.
 GAM − Information about allocated extents.
 SGAM − Information about allocated extents at system level.
 Page Free Space (PFS) − Information about free space available on pages.
 Index Allocation Map (IAM) − Information about extents used by a table
or index.
 Bulk Changed Map (BCM) − Information about extents modified by bulk
operations since the last backup log statement.
 Differential Changed Map (DCM) − Information about extents that have
changed since the last backup database statement.

Database Objects
 Table - Object that holds the relational data.

View - A view is basically a stored query. Sometimes a query can be so complex


it is created a view so that other connections can just write "SELECT * FROM view"

 Stored Procedure/Function - Both of these objects, as you would assume,


are objects that store a collection of SQL statements and other than this
one similarity they do not have much in common. Some of the key
differences are: Functions can only run SELECT and a stored procedure can

Mayukha IT Services
[email protected]
+91-9573349020
https://realtimedba.thinkific.com/courses/your-first-course\
https://www.linkedin.com/in/mayukhaitservices/
also run DELETE/INSERT/UPDATE, stored procedures can have both input
and output parameters whereas functions can only have input, functions
can be used in one or many parts of a SELECT query and stored procedures
cannot be used, stored procedures can optionally return a value whereas
function must return a value, etc.
 Index - This is a structure that can be used to speed up accessing data in a
table. Specified columns make up the index and, when specified in a
query, can help to speed up performance as the indexed column will
contain a pointer to where the rest of the data is located that makes up
that row.
 User/Login - Sometimes used interchangeably in SQL Server they are in
fact two different things. A login is used for authentication to the database
instance whereas a user is used for database/object access. Each login will
have an associated database user (most often with the same name).
 Role - An object that contains a set of permissions for objects within the
database. Can be granted to users to ease administration by not having to
grant individual permissions to each user.
 Schema - Schema can have many different meanings in a database context
but here it can be described as something that holds a collection of
objects, kind of like a container or namespace. Other objects like tables,
indexes, function, etc. can be grouped logically and assigned to a schema
on creation.

Mayukha IT Services
[email protected]
+91-9573349020
https://realtimedba.thinkific.com/courses/your-first-course\
https://www.linkedin.com/in/mayukhaitservices/

You might also like