SQL Study
SQL Study
The Resource Database (mssqlsystemresource) in SQL Server is a hidden, read-only system database that
contains all the system objects (such as system stored procedures, views, and functions) that come with
SQL Server.Key Features of the Resource Database
Stores System Objects: It contains definitions of system objects but not user data or user objects.
Hidden from Users: It does not appear in sys.databases or sys.master_files and cannot be accessed
directly.
Facilitates Upgrades: When SQL Server is upgraded, the Resource Database file
(mssqlsystemresource.mdf) is replaced instead of modifying system tables, making upgrades faster.
Shared by All Databases: The system objects defined in the Resource Database appear in each database
under sys. schema but are physically stored in the Resource Database.
Restoring the Resource Database is not possible directly; you must restore it by replacing the
mssqlsystemresource.mdf and mssqlsystemresource.ldf files from a backup.
A corrupted or missing Resource Database can prevent SQL Server from starting.
A clustered index determines the physical order of data rows in a table. Since a table’s rows can only be
stored in one physical order, SQL Server allows only one clustered index per table.
Insufficient Disk Space- - (ERROR MESSAGE) Operating system error 112 (There is not enough space on the disk)
-Permission Issues- - (ERROR MESSAGE) Cannot open backup device. Operating system error 5 (Access is denied.)
-Backup File in Use / Locked- (ERROR MESSAGE) Exclusive access could not be obtained because the database is in
use.
-Database in Use (Full Recovery Mode and Log Backup Issues)- - (ERROR MESSAGE) BACKUP LOG cannot be
performed because there is no current database backup.
- Backup Device Failure (Corrupt or Read-Only Disk)- (ERROR MESSAGE) Write failure on backup device. The device
is not ready.
The Boot Page is a special system page in SQL Server that stores critical metadata about a database. It
contains essential information such as the database version, creation date, compatibility level, and
recovery settings.
Boot Page Location:The Boot Page is always stored in Page ID = 9 of the Primary Data File (MDF).It is
present in every database and is crucial for SQL Server to recognize and manage the database.
Importance of the Boot PageThe boot page is essential for SQL Server because:
If the Boot Page is corrupted, the database may fail to start or become inaccessible.
If no backup is available, try setting the database to EMERGENCY mode and repair it
7.What is a Deadlock?
A deadlock occurs when two or more queries compete for the same resources and end up waiting
indefinitely for each other to release the locks. SQL Server detects this situation and automatically
terminates one query (the deadlock victim) to allow the other to proceed.
✅ Detect Deadlocks using Extended Events, Error Logs, or Trace Flags.
✅ Prevent Deadlocks by following consistent table access order and keeping transactions short.
A Shared Lock (S Lock) in SQL Server allows multiple transactions to read a resource (row, page, or table)
simultaneously but prevents modifications while the lock is held.
By query-
SELECT * FROM Employees WITH (HOLDLOCK);
✅ Multiple transactions can read the same data at the same time.
Blocking in SQL Server occurs when one session (SPID) holds a lock on a resource (row, page, table) and
another session waits for that lock to be released.
-Blocking is normal in SQL Server but can cause performance issues if not handled properly.
Deadlock: Two queries wait for each other → SQL Server forcefully terminates one.
1. Long-Running Transactions
2 .Missing Indexes (Causing Table Scans)
Lock escalation is the process where SQL Server automatically converts multiple fine-grained locks (row
or page locks) into a coarser-grained lock (table lock) when too many locks are acquired.
Why Does SQL Server Escalate Locks?
To reduce memory usage (tracking too many row/page locks consumes memory).
However, it can cause blocking if one session holds a table lock while others need access to different
rows.
In SQL Server, Wait Types indicate why a query or session is waiting before execution continues.
Data Masking is a security feature in SQL Server that hides sensitive data from unauthorized users while
allowing them to work with the data for testing, development, or reporting purposes.
Normally, when SQL Server creates or grows a database file, it fills the new space with zeros (to prevent
reading old deleted data).
IFI skips this zeroing process, allowing SQL Server to use the new space immediately.
Transaction log files (LDF) are not affected—they are always zeroed out for crash recovery safety.
Isolation levels control how transactions interact with each other to maintain data consistency and
concurrency.
✅ Enables new SQL Server features when using the latest level.
Types of pages
Index Page (1 & 2)-- Stores index key values and pointers
IAM Page (10)(Index Allocation Map Tracks extents allocated to tables or indexes
SGAM Page (9)Shared Global Allocation Map) Tracks mixed extents with free space
DCM Page (6) Differential Changed Map -- Tracks modified extents for differential backups