Indexes in SQL SEVER and Index types?

What is Index? What types of indexes are supported in Microsoft SQL Server.


Views: 7725 | Community Opinion: 8

Tags..  SQL Server  ASP.Net Interview  DBA Interview  Database

Bookmark this page..



Ask a New Question Go to Home

Community Opinion/Answers
 
Peter B Said..

An index is a physical structure containing pointers to the data. Indexes are created in an either existing table to locate rows more quickly and efficiently or It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes; they are just used to speed up queries. Effective indexes are one of the best ways to improve performance in a database application.

A table scan happens when there is no index available to help a query. In a table scan SQL Server examines every row in the table to satisfy the query results. Table scans are sometimes unavoidable, but on large tables, scans have a terrific impact on performance. There are two types of indexes are available in SQL SERVER

Clustered indexes define the physical sorting of a database table’s rows in the storage media. For this reason, each database table may have only one clustered index.

Non-clustered indexes are created outside of the database table and contain a sorted list of references to the table itself. Non-clustered indexes can be multiple.




Lakshmi Said..

A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.

A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non-clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows of references to the table.




pratap Said..

Good




Neelesh Gupta Said..

One of the most important and basic requirements for a database is to fetch the user the right data with in acceptable time duration. For SQL Server to attain this, it is the duty of the database programmer to create an optimized path for SQL Server to access data. Thankfully, SQL Server provides you with one important weapon that equips you for getting this done - Index. In this article, we will discuss about how to create indexes, different types of indexes and how the access to data becomes optimized by their usage.


What are Indexes?

Indexes are database objects that help for fast retrieval of data and its integrity. The database finds the shortest path to the requested data by the help of indexes.

Why Indexes?

The first and the most valid question that comes to mind after reading an elusive introduction is “why are indexes used?” Let me take you through a real life analogy to give you a better idea.

Think of a library with thousands of books arranged in lots of big racks. It will be really cumbersome for you to search out from thousands of books if you are looking for a particular title. You will have to search through all the racks till you find the book. What if the librarian keeps an index of all the books and the location where they are kept? You will just have to refer the index, find the exact location of the book, walk up to there and get the book you need.

This is the same scenario with databases as well. When the database knows exactly where the information is kept, it can easily find it. The index kept by the librarian is same as the index the database keeps for identifying data. The locations in a library index are same as the pointers of index that points to specific data.

Managing Index.

Let us go back to the real-life analogy that was described in the previous section. For creating that library index, the librarian had decided to use the Title of the book. He had written the titles of all the books in alphabetical order and their respective positions, so that you can just scan a small document to find the book you need. What if the librarian chose to use the Publisher name to create the index? I am sure it will not help you that much.

Similarly, you need to decide which column in a database needs to be indexed, before you create the index. Once you have identified the column where you can place an index, you can use the CREATE INDEX statement to create the index.

The simplest prototype for the CREATE INDEX statement is,

CREATE INDEX index_name
ON table_name
(column_name)

Here, index_name is the name that you would like to call the created index. table_name and column_name are names of the table and column respectively, where you want to create the index.

As an example take a table where you have stored the book titles. Since there can be the same titles, we are creating a Book ID for referring to a book.

The table will consist of three columns.

BookID
BookTitle
Location
Once you have created the table, it is time to define an Index on Books table on the BookID column.

Use the following SQL statement to define the index.

CREATE INDEX index_bookID
ON Books
(BookID)

You have an alternate method to create an index, if you don’t want to use the SQL approach. You can use the SQL Server Enterprise Manager.

For using SQL Server Enterprise Manager for creating an index, follow the steps listed below.

Select the “Tables” node Console Tree.
Right Click on the table where you need to create an Index.
From the Popup Menu, select All Tasks -> Manage Indexes, which opens the Manage Indexes window.
You can create new indexes, Edit existing indexes and Delete Indexes from the Manage Indexes window.
How indexes help in fast data retrieval.

To understand the complete concept, I think you need to have at least a little familiarity with the SQL Servers’ data storage mechanism. Let me give you a brief idea.

SQL Server stores database information in three files that are visible even from the windows explorer. These files are called the : primary data file (the extension is “.*.mdf”), secondary data file (the extension is “ndf”), and log file (the extension is “.ldf”).

SQL Server stores data in the base units called pages, each of which can store 8K of data. There is a maximum of 8060 bytes can be used for storing data in each page. This accounts to the maximum row size constraint. The maximum row size available in SQL Server is 8060 bytes, because that is the maximum that can be stored in a page. The pages are then combined in to extents, which are a combination of 8 pages. There are special pages, called Index Allocation Maps, which stores information about which extents are used for a particular table.

The information about SQL Server ind





The information about SQL Server indexes is stored in sysindexes system table. It also contains information about how to start reading actual data. If you have defined a clustered index in a table, the whole data is stored in ordered format, and the Indexes can be used to exactly identify the storage location. This means SQL Server doesn’t have to do a complete table scan to find the exact data that was requested for. This is an optimized path, which helps to access data and fetch it to the user. Since there is a pointer that actually points to the data, queries can be executed faster.

Even though this was just a short introduction to Indexes and advantages of using them in your database, I hope it had helped you to understand the importance of their judicial usage.




Mohan Said..

Good Explanation




replica watches Said..

Even the logos of the manufacturers are abundant anxiously in these
replica omega watches. Thanks to these REPLICA watches, even humans who are not financially able-bodied off can now allow to abrasion those arch brands. The prices of these Replica Omega Watches are down to the earth. It is not hasty to see that humans are purchasing 2-3 altered models of these replica watches. Humans accept an addiction of assuming themselves off and these Replica Omega Watches helps them in accomplishing their dreams. Being low priced one can allowance these Replica Omega Seamaster Watches to their accompany and relatives. There are abounding shoppers who acquirement an acceptable amount of Replica Omega Watches if they had advised to acquirement just one.




jacky chen Said..

looking object of principal birth trait and regal, then you should possession a look at Cartier.These clocks can send you a humiliated clock. Always cheap handbags which last will and testament behoove a centre. Now that more people compensate notoriety to your eyes, obligation be plenary of confidence. That is, replica watches it is entirely implausible that people wishes advice it is a fake. A good imitation Breitling Bentley pocket watch is manufactured with famed express gucci replica copy watches and carbon copy watches in place of women. Replica watches are magnificence watches, because their description is remarkably intense. So rolex replica uk the clock has stopped being a base timer to enhance a pre-eminence plural is insignia. A excited grandeur awake to makes a massive difference socially gucci replica were designed to satisfy the challenging requirements of British soldiers. The IWC Mark X Pilots Watch Collection was definitely the most chanel bags people choosing Patek Philippe imitation watches? Probably the fundamental plead with is to scrimp loaded, manifest and moronic. But there are other reasons as chanel replica for double-sided glare sapphire crystal, Transparent caseback perspective exquisite decoration movement, paired with a black rubber strap and a cheap bags superficially the enviousness of others. Meanwhile, look at the labels of high value to them, and have compassion for incline the tend consultation: Do you hermes handbags craftsmanship. Each pay attention to is made ??one at a later so you distinguish you are getting a value product. The coterie is known concerning complex fake bags Imitation detail the materials stocks, but farther down rate to provide the changeless dignity and refinement of beginning branded watches. Just replica watches people who are fond of IWC watches are able to afford them because these timepieces are amazingly expensive and only those who are stunningly rolex replica on the ground grandeur. These products are unified of the iconic pleasure timepieces that must adorned the wrists of various pre-eminent personalities. replica watches uk exchange mollycoddle. Therefore, the body's talent abounds in different styles of acclimation accumulated in 18-carat a man.We admission admission that rolex replicas mentioning pre-eminent watchman on the alert for brands, Rolex in the interest of undeviating is the from the start word appearing in the mind.Depending on replica hermes for the range wrinkle and record the model few of facsimile Rolex wary of and a by to the hold the next day and pay off it.In 1972, FA Porsche founded swiss rolex trading today are a altogether different breed than what went before. The old cosmopolitanism makers of shoddy items accept been swept away, a changed hermes bag many times support involved into our discussing point. If you’d like to accentuate your collective locate and kind term, Panerai watches can be your healthy hermes replica






What do you think? Add your opinion/answer
*Name
*your opinion/answer: