Day 10 SQL Notes Basic To Advanced (SQL Indexes)
Day 10 SQL Notes Basic To Advanced (SQL Indexes)
Example:
2. Unique Index
A unique index ensures that all values in the indexed
column(s) are unique. It is often used to enforce
uniqueness constraints.
Syntax:
10.2 Creating Indexes:
Creating indexes in SQL involves defining an index on
one or more columns of a table to improve query
performance. Here’s a step-by-step guide to creating
various types of indexes:
Example:
2. Unique Index
A unique index ensures that all values in the indexed
column(s) are unique. It is often used to enforce
uniqueness constraints.
Syntax:
Example:
3. Composite Index
A composite index (or multi-column index) is created on
multiple columns. It is useful for queries that filter or
sort on multiple columns.
Syntax:
Example:
4. Clustered Index
A clustered index determines the physical order of data
in the table. A table can have only one clustered index.
Syntax:
Example:
5. Full-Text Index
A full-text index is used for efficient searching of
text within large text columns.
SQL Syntax (SQL Server):
Example:
6. Spatial Index
A spatial index is used for spatial data types to enable
fast querying of geographic data.
SQL Syntax (SQL Server):
Example:
Example:
Data rows are stored in the order Indexes are stored separately
Data Storage
of the clustered index key. from the data rows.
The index is the actual table with The index contains pointers to
Index Structure
sorted data. the actual data rows.