create index in sql server

How to Create Index in SQL Server

Database indexes allow you to speed up SQL queries and improve database performance. In this article, we will look at how to create index in SQL server.


How to Create Index in SQL Server

Here are the steps to create index in SQL Server. Here is the syntax of CREATE INDEX statement in SQL Server

create index index_name 
on table_name(column1, column2, .., columnN);

In the above query, you need to specify name of your index, name of your table for which you want the index to be created, and comma-separated list of columns to be included in your index.

You can have one or more database columns in your index.

Also read : Top 5 Free Database Design Tools


Let us say you have a table orders(id, order_date, amount), here’s the SQL query to create index order_id on orders table for id column.

CREATE INDEX order_id
on orders(id);


Here’s the SQL query to create index on multiple columns.

CREATE INDEX order_date_id
on orders(id, order_date);

Also read : How to Alter Column from NULL to NOT NULL


You can also create index for only rows that match a certain condition. Here’s an example to create index for rows with order_date>’2020-01-01′

CREATE INDEX order_date_id
on orders(id, order_date)
where order_date > '2020-01-01';

As you can see, it is very easy to create index in SQL server.

Leave a Reply

Your email address will not be published. Required fields are marked *