我有一个大型库存系统,而且我不得不重新编写它的一部分I/O部分。它的核心是一张产品表格和一套相关的表格。我需要能够尽可能有效地阅读它的部分内容。从C#我建立这个查询:从多个连接表的子集中加载DataSet的最有效方法
select * -- includes productid
into #tt
from products where productClass = 547 -- possibly more conditions
select * from #tt;
select * from productHistory where productid in (select productid from #tt);
select * from productSuppliers where productid in (select productid from #tt);
select * from productSafetyInfo where productid in (select productid from #tt);
select * from productMiscInfo where productid in (select productid from #tt);
drop table #tt;
该查询给我完全的结果,我需要:5的结果集每个都具有零,一个或多个记录(如果第一个返回零行,别人做的一样好,的课程)。然后该程序将这些结果集合并将它们拼凑成合适的DataSet
。 (然后将其交给构造函数,期望这些记录)。此查询(具有不同的条件)将运行lot。
我的问题是,是否有更有效的方式来检索这些数据?
将此作为单个连接重新工作将不起作用,因为每个子可能会返回可变数量的行。
一旦我找到了解决这个问题的最佳方法,我可能会将其解释为SP。至少在查询计划已经编译的地方。 –