日期:2014-05-18  浏览次数:20579 次

下面这句SQL能不能优化一下
delete   Forum_Vote   where   VoteID   in   (select   VoteID   from   Forum_Vote   where   Topic_ID= '+@Topic_ID+ '   and   VoteID   not   in( '+@VoteIDs+ '))

------解决方案--------------------
delete Forum_Vote
where exists
(select 1 from Forum_Vote
where Topic_ID= '+@Topic_ID+ '
and VoteID not in( '+@VoteIDs+ ') and VoteID=Forum_Vote.VoteID)
------解决方案--------------------
用關聯可能效率好些

Delete A From Forum_Vote A
Inner Join
(select VoteID from Forum_Vote where Topic_ID= '+@Topic_ID+ ' and VoteID not in( '+@VoteIDs+ ')) B
On A.VoteID = B.VoteID