在 SQL Server 2008 上索引表的主要优点是什么?
请用例子说明(如果可能的话)..
由于
答案 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)
想到的几个可能的优点
答案 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