为什么执行速度会不同?
数据库表StockInOutDtl有10万条记录,我在存储过程中执行下列语句只用了1秒:
insert into @tmpStock
SELECT B.ArtID , B.ArtDesc , B.Units , -B.Qty as Qty , 0, A.ST
From StockInOut A Left Outer Join StockInOutDtl B
On A.SheetID=B.SheetID
Inner Join RefArtList C On B.ArtID=C.ArtID
Where A.IssueDate> =@RenewDate
And B.ArtID=@ArtID
但没有 "Inner Join RefArtList C On B.ArtID=C.ArtID "一行,即下列语句却要9秒:
insert into @tmpStock
SELECT B.ArtID , B.ArtDesc , B.Units , -B.Qty as Qty , 0, A.ST
From StockInOut A Left Outer Join StockInOutDtl B
On A.SheetID=B.SheetID
Where A.IssueDate> =@RenewDate
And B.ArtID=@ArtID
------解决方案--------------------没有 "Inner Join RefArtList C On B.ArtID=C.ArtID "一行
要插入的记录要多一些
------解决方案--------------------楼主可以看一下执行两个SQL语句后所影响的行数
------解决方案--------------------没有关联条件结果积当然大