0% found this document useful (0 votes)
5 views5 pages

Index

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Index

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL server Indexes

Eg: CREATE TABLE parts(


part_id INT NOT NULL,
part_name VARCHAR(100));

• Parts table does not have a primary key, therefore, SQL Server stores
its rows in an unordered structure.
• When you query data from the table, it needs to scan the whole table
to locate the correct one.
Types of indexes
• SQL Server has two types of indexes:
1. Clustered index
2. Non-clustered index

3. Clustered index: A clustered index stores data rows in a sorted structure based
on its key values. Each table has only one clustered index.
• When you create a table with a primary key, SQL Server automatically creates a
corresponding clustered index based on columns included in the primary key.
Eg:
• The following statement creates a clustered index for the parts table.

CREATE CLUSTERED INDEX ix_parts_id


ON parts (part_id);
2. Non-clustered indexes: A non-clustered index is a data structure that
improves the speed of data retrieval from tables.

Eg: CREATE INDEX ix_customers_city


ON customers(city);

• Create a non-clustered index for multiple columns example.

Eg: CREATE INDEX ix_customers_name


ON customers(last_name, first_name);

You might also like