Querying Data With Transact-SQL Part 03 (1)
Querying Data With Transact-SQL Part 03 (1)
Management System
Querying Data with Transact-SQL
1) What is An index?
2) B-tree index structure
3) Clustered Tables vs Heap Tables
4) Types of Indexes
5) Clustered index
6) Non Clustered index
7) Unique index
8) Filtered index
9) Covered index
10) Index Fragmentation
11) Rebuild vs. Reorganize Strategy
12) Fill factor
13) Introduction to SQL Server indexed view
Heap Tables
• Data is not stored in any particular order
• Specific data can not be retrieved quickly, unless there are also
non-clustered indexes.
• Data pages are not linked, so sequential access needs to refer
back to the index allocation map (IAM) pages
• Since there is no clustered index, additional time is not needed
to maintain the index
• Since there is no clustered index, there is not the need for
additional space to store the clustered index tree
• These tables have a index_id value of 0 in the sys.indexes
catalog view
CONFIDENTIAL | © 2020 EPAM Systems, Inc.
CONFIDENTIAL | © 2020 EPAM Systems, Inc.
CLUSTERED TABLES VS HEAP TABLES
Clustered Table
• Data is stored in order based on the clustered index
key
• Data can be retrieved quickly based on the clustered
index key, if the query uses the indexed columns
• Data pages are linked for faster sequential access
• Additional time is needed to maintain clustered
index based on INSERTS, UPDATES and DELETES
• Additional space is needed to store clustered index
tree
• These tables have a index_id value of 1 in the
sys.indexes catalog view
• Clustered index
• Non Clustered index
• Unique index
• Filtered index
• Covered index
• MS Sql Server:
CREATE INDEX -> Non-Clustered by default
• Allowed more than one index on a db table
• MS Sql Server 2008:
up to 999 Non-Clustered indexes per table
• An index that ensures the uniqueness of each value in the indexed column.
• A unique index ensures that the index key contains no duplicate values.
• Both clustered and nonclustered indexes can be unique.
• If the index is a composite, the uniqueness is enforced across the columns as
a whole, not on the individual columns.
• A unique index is automatically created when you define a primary key or
unique constraint:
o Primary key
o Unique
CONFIDENTIAL | © 2020 EPAM Systems, Inc.
COVERING INDEXES