如何选择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