Home » SQL

SQL INDEX - To speedup data retrieval operations

In this article, we are going to learn what is SQL INDEX, how to create and use INDEX in SQL? How it speeds up the data retrieval?
Submitted by Shubham Singh Rajawat, on December 02, 2017

Indexes are special structures, which are made to speed up data retrieval operations on a database table. Indexes speed up the querying process by giving swift access to the rows of a table, it is similar to a book’s index which gives us direct access to any content inside the book.


CREATE [UNIQUE] INDEX <index_name> ON <table_name> (<columns>);


  • UNIQUE - defines index as unique constraint. It doesn’t allow any duplicate values
  • Index_name - Name of the index table
  • Table_name - Name of base table
  • Columns - Name of columns

There are two types of architectures in SQL

1. Clustered

In clustered architecture index values are stored in sorted manner i.e. either in ascending or descending order. Only one clustered index can be made per table.

Clustered indexes are stored physically on the table,that’s why access to them is faster i.e. Data retrieval is faster compare to non-clustered indexes.

2. Non-clustered

Data is present in arbitrary order, do not affect the physical order, create a logical order and use pointers to physical data files i.e. Data rows are spread throughout the table regardless of the value of the indexed column.We can make more than one non-clustered index per table.

Non-clustered indexes are stored separately from the table. Access to them is slower but update and insertion operations are faster on them as compare to clustered index.

Sample table

sql index tutorial

Types of Indexes

1. Composite Index

An index that contains more than one columns. It can be clustered or non-clustered.


CREATE INDEX UniqueId ON Student(Enroll_No, DOB);


Index created

2. Unique Index

Unique index ensures the uniqueness in each value in the indexed column.


CREATE UNIQUE INDEX EnrollmentNo ON Student(Enroll_No );


Index created

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.