开发者

SQL Server 2008 - Advantages of Indexing the tables

What are the main advantages of indexing the tables on SQL Server 2008?

Ple开发者_Python百科ase explain with examples (if possible)..

Thanks


Indexing provides a way to improve the performance of your data access queries. Suppose you have a table with different identifying columns. Putting an index on each column, or combinations of columns that are queried together will improve your response time.

Example: you have a User table with columns:

FirstName | LastName | ZipCode

Put an index on LastName if you are querying on last name, such as:

SELECT * FROM User where LastName = 'SMITH'

Index could be:

CREATE NONCLUSTERED INDEX [MyIndex] ON [User] 
(
    [LastName] ASC
) WITH (
    PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
    SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, 
    ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON
) 
ON [PRIMARY]

Or, put an index on 2 columns if you are querying these columns together:

SELECT * FROM User where LastName = 'SMITH' and ZipCode = '14222'

Index could be:

CREATE NONCLUSTERED INDEX [MyIndex] ON [User] 
(
    [LastName] ASC,
    [ZipCode] ASC
) WITH (
    PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
    SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, 
    ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON
) 
ON [PRIMARY]

All else equal, your queries will be faster if you create the index. Be careful though, too many indices may actually decrease performance.


The same as indexing a book. If you need to find something quickly SQL Server can do a lookup instead of reading every row from the table.

Imagine if you had to lookup something in a book and didn't have an index? Same principle


A few possible advantages that spring to mind

  1. Can be used to quickly locate specific rows or ranges of rows.
  2. Even if the index cannot be used to match the seek predicate directly it can be used to limit the number of pages read (can be quicker to scan a narrower covering non clustered index than the whole table)
  3. Can be used to avoid a sort operation by providing the data pre-sorted


Advantages:

1.Index Plays major role when a data is to be searched in Bulk Records
2.When data is searched in a table , it uses "sequential search technique, which
  is always a time consuming process ( Or ) it leads to wastage of time.
3.When ever finds the value, it stops the searching process
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜