如何選擇SQL指數如何選擇SQL指數
我有一個領域c_ID (primary key)
,並c_Emp_ID
的表TabEmp。
我創建的索引上idx_TabEmp (non-clustered)
與領域c_ID (primary key)
和c_Emp_ID
我使用select語句
select * from index = idx_TabEmp
它拋出一個錯誤
Incorrect syntax near 'index'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See SQL Server Books Online for proper syntax
我使用
select * from TabEmp (index = idx_TabEmp)
它的工作原理,但我不確定這是否是選擇索引的正確方法
您能否告訴我查詢索引的正確方法?
優化程序應該自動使用索引,如果它將有利於查詢。查看執行計劃以確定正在使用的索引。 – 2010-12-03 15:43:22
在SQL Server中,您不需要/通常不指定要使用的索引--SQL Server的查詢優化器會自動計算出來。只要做你的'SELECT(列表)FROM(tablename)`,並且如果索引有幫助,SQL Server就會使用它' – 2010-12-03 15:53:15