SQL Database Engine Storage

This section details the storage mechanisms and concepts within the SQL Database Engine. Understanding how data is stored is crucial for performance, scalability, and manageability of your databases.

Core Storage Concepts

Data Files and Log Files

Every SQL Server instance utilizes at least two types of physical files to store database information:

Filegroups

Filegroups are logical containers for one or more data files. They provide a way to manage and allocate space for data storage. The primary filegroup is always present and contains the primary data file. You can create user-defined filegroups to place specific tables and indexes on different physical storage devices for performance or administrative reasons.

Pages

The smallest unit of storage in SQL Server is a page, which is 8 KB in size. All data and index information is stored on pages. A page is composed of 96 bytes of header information and 8096 bytes for the actual data. A row can span multiple pages if it's too large to fit on a single page.

Note: Understanding page structure helps in optimizing queries and diagnosing performance issues related to I/O.

Storage Management

Data Allocation and Extents

When data is inserted into a table, SQL Server allocates space using extents. An extent is a set of eight contiguous pages (64 KB). There are two types of extents:

Row Storage

Data within a page is organized into rows. SQL Server supports two primary row storage formats:

Indexes

Indexes are special lookup tables that the database search engine can use to speed up data retrieval operations. They are stored similarly to data but are optimized for searching and sorting.

Tip: Properly designed indexes are critical for query performance. Analyze query execution plans to identify missing or redundant indexes.

Advanced Storage Features

Partitioning

Table and index partitioning allows you to divide large tables and indexes into smaller, more manageable units called partitions. This can improve performance for specific queries, simplify maintenance operations, and reduce the impact of data archiving.

Compression

SQL Server offers both Row and Page compression to reduce the physical storage space required for data. This can lead to improved I/O performance and reduced storage costs.

Filestream

The FILESTREAM feature integrates your SQL Server database with an NTFS file system. It allows you to store large unstructured data objects, such as documents and images, as files in the file system while still maintaining transactional consistency with the relational data in SQL Server.

Best Practices