SQL: What is an Index?

Today, I want to talk about Indexes.  What is an Index in SQL?

An index is to find something in a database much faster.  When you think about an index at a library using a catalog, it uses an index to find a book faster.  You can also search for a particular topic using an index to find things quicker.  Each book has an index located in the front pages right after the title page to help the reader find a chapter or subject on a certain page.

In this case, using an index in SQL is similar to any index either in a book or a library.  Without them you would spend too much time flipping through each page to find the object you need.

What is an index?

An Index can be created on a single column or a combination of columns in a database table. A table index is a database structure that arranges the values of one or more columns in a database table in specific order. The table index has pointers to the values stored in specified column or combination of columns of the table. These pointers are ordered depending on the sort order specified in the index.

Example:  Here’s how to write an index in SQL

CREATE INDEX index_name
ON table_name (column1, column2, …);

 

How to drop an index

DROP INDEX index_name ON table_name;

 

Thoughts?

How has indexes helped you?  Was this helpful?

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s