SQL Server 2008 - 索引表的优点

时间:2011-10-04 17:07:07

标签: sql-server-2008

SQL Server 2008 上索引表的主要优点是什么?

请用例子说明(如果可能的话)..

由于

4 个答案:

答案 0 :(得分:10)

索引提供了一种提高数据访问查询性能的方法。假设您有一个包含不同标识列的表。在每个列或一起查询的列组合上添加索引可以缩短响应时间。

示例:您有一个用户表,其中包含列:

FirstName | LastName | ZipCode

如果要查询姓氏,请在LastName上添加索引,例如:

SELECT * FROM User where LastName = 'SMITH'

指数可能是:

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]

或者,如果要同时查询这些列,请在2列上添加索引:

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

指数可能是:

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]

除此之外,如果您创建索引,您的查询会更快。但要小心,太多的指数实际上可能会降低性能。

答案 1 :(得分:2)

与索引书籍相同。如果您需要快速查找内容,SQL Server可以执行查找而不是从表中读取每一行。

想象一下,如果你不得不在书中查找某些内容而没有索引?相同的原则

答案 2 :(得分:1)

想到的几个可能的优点

  1. 可用于快速定位特定行或行范围。
  2. 即使索引不能直接用于匹配搜索谓词,也可以用来限制读取的页数(可以更快地扫描覆盖非聚集索引的覆盖范围比整个表更窄)
  3. 可以通过提供预先排序的数据来避免排序操作

答案 3 :(得分:0)

优点:

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