What are an Index in SQL Server and all developer use indexing in the database?

What are an Index in SQL Server and all developer use indexing in the database?

Last updated:9/22/2021 1:16:59 AM

1 Answers

Ashutosh Kumar Verma
Ashutosh Kumar Verma

SQL INDEX:

  SQL Create Index statement is used to create Indexes in database table. Indexes are used to retrieve data from database table more quickly than other ways. The user can not see indexes they just used it to speedup searches/queries.

Updating a table with indexes take more time than update table without indexes because indexes also need to update, so index only created on column that will be searches frequently.

There are also duplicated values are allowed in the index.

Syntax for Create Index-

CREATE INDEX index_name

ON table_name(column1, column2,…);

Create Unique Index:

When create unique index on a table it does not allowed duplicate values.

Syntax-

CREATE UNIQUE INDEX index_name

ON table_name(column1, column2,….);

Example:

 Lets take a database table ‘Student’

What are an Index in SQL Server and all developer use indexing in the database?

Now, create an Syntax on above table like as,

create index indexStudent

ON Student (stuName);

To create index on multiple column in a table the following SQL statement is used. It created on other database table ‘StudentRecord;.

create index indexStudent

ON StudentRecord (stuName, stuCourse);

DELETE Index:

DROP INDEX table_name.index_name;

Example:

drop index Student.indexStudent;


Answer