比较不同查询语句使用索引的情况
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
创建非聚集索引,非唯一索引。
索引的优点是方便查找;例如在大型数据库中想要找到自己所需要的文件或者表单,是非常麻烦的,为了避免减少这种情况出现,可以利用针对表单来创建索引以方便查找;下面为针对表单创建索引的简单步骤与应用;
1、 索引名为IX_Startdate(startdate)
创建索引IX_Workorder_ProductID2(ProductID)
2,索引名为IX_Startdate(startdate)
3,创建索引名为:IX_Workorder_ProductID2(ProductID);
4,创建完成后,在WorkOrder表,索引目录下将会出现新建索引;
5,在新建查询中,执行Select * from Production.workorder where productid=732
查看使用的是哪个索引来进行查找。
6,执行Select * from Production.workorder where productid>732
查看使用哪个索引来进行查找。
7,禁止索引,选择需要禁止的索引,右击—选择—禁止.
8,然后在禁止索引之后。执行Select * from Production.workorder where productid>732.查看使用哪个索引来进行查找。查看有什么变化.
9,如果表中存在索引过多。从而导致查找信息时速度过慢,可以使用强制使用索引来,解决这一问题,从而更方便快捷查找,具体如下:
执行Select * from Production.workorder where productid>732
查看使用哪个索引来进行查找。
例如:需要使用PK_WorkOrder_WorkOrderID索引来进行查找,具体语句写法如下:
Select * from Production.workorder
with (index(PK_WorkOrder_WorkOrderID))
where productid>732;
转载于:https://blog.51cto.com/qiangmeng/291188