字段任意组合查询 复合索引如何建? 一个表tb:id int,tid int,tidp int,cid int,cidp int id上建聚集索引 数据库里保存50万数据:tid>0,tidp>0,cid>0,cidp>0
有这样的查询
--...tid,tidp,cid,cidp任意组合 select id from tb where tid=2 and cidp=3; select id from tb where tid=2 and cid=4; select id from tb where tidp=1; select id from tb where cidp=3;
建立复合索引tid asc,tidp asc,cid asc,cidp asc 我想写这样的查询 select id from tb where tid=1 and cid=2 and tidp>0 这里【特意加的tidp>0】是为了想让利用上索引上的cid可行吗? 如果不能利用上cid 这样的索引要怎么样建呢? 复合索引;建索引;sql?server [解决办法] 你这组合太多建议多建几个索引 不要搞一个复合四个字段的 tid如果出现很多 下面的就可以 on tb(tid) include(tidp ,cid ,cidp)