Skill 1.1.1

Design and implement tables, including data types, size, columns, indexes, and columnstore indexes

Key Concepts

Each column should use the smallest data type that holds every valid value. Integer keys use int (up to about 2.1 billion) or bigint; money uses decimal(p,s) rather than float, which is approximate; dates use date, datetime2 or, when the offset from UTC matters, datetimeoffset. International text uses nvarchar, or varchar with a UTF-8 collation, and max types are reserved for values that can exceed 8,000 bytes. SQL Server 2025, Azure SQL Database and SQL database in Fabric add the json type for JSON documents and the vector type for embeddings. A row's in-row data is limited to 8,060 bytes, so oversized variable-length values move to row-overflow or LOB pages, which costs extra reads.

The clustered index defines the order in which rows are stored, and a table has at most one; a narrow, unique, ever-increasing key such as an int identity works best. Nonclustered indexes are separate B-trees that speed up seeks on other columns; INCLUDE columns make an index covering, and a WHERE clause makes it a filtered index over a subset of rows. Columnstore indexes store each column separately in compressed rowgroups of up to 1,048,576 rows and process rows in batches, so scans and aggregations over large tables become much faster. A clustered columnstore index makes the whole table columnar, which suits fact tables; a nonclustered columnstore index adds an analytical copy to a rowstore OLTP table for real-time operational analytics.