平时都是用第三种查询,今天看了SQL必知必会 第4版,作了几次查询实验。原来在一般情况下,还是用嵌套查询时间快些:

 set statistics time on;

 select * from ICBOMChild 

 where FInterID in (select FInterID 

from ICBOM 

where FItemID in (select FItemID 

 from t_ICItem 

 where FNumber like'9.9250.%'))

SQL Server 分析和编译时间: 

   CPU 时间 = 13 毫秒,占用时间 = 13 毫秒。


 SQL Server 执行时间:

   CPU 时间 = 0 毫秒,占用时间 = 0 毫秒。


(272 行受影响)


 SQL Server 执行时间:

   CPU 时间 = 0 毫秒,占用时间 = 3 毫秒。

--------------------------------------------------------------------------------------------------------------------


select * from ICBOMChild t1 join ICBOM t2 on t1.FInterID=t2.FInterID join t_ICItem t3 on t2.FItemID=t3.FItemID and t3.FNumber like '9.9250.%'


SQL Server 分析和编译时间: 

   CPU 时间 = 0 毫秒,占用时间 = 0 毫秒。


(272 行受影响)


 SQL Server 执行时间:

   CPU 时间 = 32 毫秒,占用时间 = 395 毫秒。

----------------------------------------------------------------------------------------------------------------------


set statistics time on;

select * from ICBOMChild t1,ICBOM t2,t_ICItem t3   where t1.FInterID=t2.FInterID and t2.FItemID=t3.FItemID and t3.FNumber like '9.9250.%'


SQL Server 分析和编译时间: 

   CPU 时间 = 31 毫秒,占用时间 = 41 毫秒。


 SQL Server 执行时间:

   CPU 时间 = 0 毫秒,占用时间 = 0 毫秒。


(272 行受影响)


 SQL Server 执行时间:

   CPU 时间 = 32 毫秒,占用时间 = 46 毫秒。