Header Ads Widget

SQL Index

SQL Index

  • Indexes are special lookup tables. It is used to retrieve data from the database very fast.
  • An Index is used to speed up select queries and where clauses. But it shows down the data input with insert and update statements. Indexes can be created or dropped without affecting the data.
  • An index in a database is just like an index in the back of a book.
  • For example: When you reference all pages in a book that discusses a certain topic, you first have to refer to the index, which alphabetically lists all the topics and then referred to one or more specific page numbers.

1. Create Index statement

It is used to create an index on a table. It allows duplicate value.

Syntax

  1. CREATE INDEX index_name  
  2. ON table_name (column1, column2, ...);  

Example

  1. CREATE INDEX idx_name  
  2. ON Persons (LastName, FirstName);  

2. Unique Index statement

It is used to create a unique index on a table. It does not allow duplicate value.

Syntax

  1. CREATE UNIQUE INDEX index_name  
  2. ON table_name (column1, column2, ...);  

Example

  1. CREATE UNIQUE INDEX websites_idx  
  2. ON websites (site_name);  

3. Drop Index Statement

It is used to delete an index in a table.

Syntax

  1. DROP INDEX index_name;  

Example

  1. DROP INDEX websites_idx;  

Post a Comment

0 Comments