因为程序需要,会用到这样的查询语句“select * from table1 where id in (1,3,6,10,...,8000) and type = 1”,id值可能有数千个之多,这样查询起来非常慢,把id设为主键也很慢,请问有没有什么方法可以快一点?
---------------------------------------------------------------
select id into #temp form table1 where ...
select table1.* from table1
inner join #temp on #temp.id = table1.id
where type = 1
drop table #temp
go
---------------------------------------------------------------
如楼上,你可以先声明一个临时表,
Create #temp(ID int)
然后把你的ID值循环加进临时表,再参见楼上
select table1.* from table1
inner join #temp on #temp.id = table1.id
where type = 1
drop table #temp
go