Skill 1.1.6

Design and implement partitioning for tables and indexes

Key Concepts

A partition function maps a column's values to partitions with boundary values and RANGE LEFT (the boundary belongs to the left partition) or RANGE RIGHT (to the right partition); RANGE RIGHT is natural for dates, so each boundary is the first day of a period. A partition scheme maps partitions to filegroups; Azure SQL Database supports only the PRIMARY filegroup, so schemes use ALL TO ([PRIMARY]). The table or index is created ON scheme(column), and the partitioning column must be part of every unique index key, including the primary key.

When nonclustered indexes are aligned (partitioned on the same scheme), whole partitions can be moved with ALTER TABLE ... SWITCH, removed with TRUNCATE TABLE ... WITH (PARTITIONS (n)), and rebuilt one at a time. Queries that filter on the partitioning column benefit from partition elimination. SPLIT RANGE and MERGE RANGE add and remove boundaries in a sliding window, and $PARTITION.function(value) returns the partition number for a value.