日期:2014-05-19  浏览次数:20468 次

sqlserver 关于索引
表结构如下


CREATE   TABLE   [dbo].[Flow_Info_List]   (
[Flow_Id]   [int]   IDENTITY   (1,   1)   NOT   NULL   ,
[Flow_Time]   [datetime]   NULL   ,
[Flow_Name]   [nvarchar]   (50)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[Flow_Bc_Id]   [int]   NULL   ,
[Flow_Dz_id]   [int]   NULL   ,
[Flow_X]   [nvarchar]   (50)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[Flow_Out_Time]   [datetime]   NULL   ,
[Flow_In_Out_Flag]   [int]   NULL   ,
[Flow_In_Time]   [datetime]   NULL   ,
[Flow_Dept_Child_id]   [int]   NULL   ,
[Flow_In_User]   [nvarchar]   (50)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[Flow_Out_User]   [nvarchar]   (50)   COLLATE   Chinese_PRC_CI_AS   NULL  
)   ON   [PRIMARY]
GO


[Flow_Name]  
[Flow_Bc_Id]  
[Flow_Dz_id]  

[Flow_Dept_Child_id]
和外部要关联查询

[Flow_Name]  
[Flow_Bc_Id]  
[Flow_Dz_id]  

[Flow_Dept_Child_id]

[Flow_Time]在   where   里作为条件

用什么类型的索引比较好。




------解决方案--------------------
Flow_Time 上用聚集索引。
个人感觉 Flow_Time上最好为 not null , 在where条件下 null 值不显示。

也可以考虑在
[Flow_Name]
[Flow_Bc_Id]
[Flow_Dz_id]

[Flow_Dept_Child_id] 等 外键上做聚集索引,
要看你经常查询的条件了。
毕竟聚集索引只有一个,要珍惜利用。

------解决方案--------------------
查询条件用的最多,排序用的最多的字段用聚集索引,与外表做连接的字段不需要索引。
Flow_Time如果在查询条件中没有的话,没有必要加索引,如果不是很精通,建议还是用在主键上
------解决方案--------------------
"与外表做连接的字段不需要索引 "
================================
错的,需要.不然很慢的.

我觉得你随便建个索引就行了,聚集索引一般都被主键占了,所以你也没什么选择了.