Hi,
Can you let me know, which of the following query execution gives better performance.
Also, the table T1 is not indexed and the table can have 100,000 records.
Case 1:
DELETE FROM T1 where NAME = 'Ayyappan'
DELETE FROM T1 where NAME = 'Manivel'
Case2:
DELETE FROM T1 where NAME in ('Ayyappan', 'Manivel')
Loading

Anuja PawarRank #1,404 · 1.2K reputationPosted Nov 30, 2011, 4:20 AM EST
Refer this thread to clear your doubts
http://stackoverflow.com/questions/7486856/disadvantages-of-in-operator-in-sql-server-and-alternate-way-not-to-use-in-opera
Anuja PawarRank #1,404 · 1.2K reputationPosted Nov 30, 2011, 4:23 AM EST
http://www.bennadel.com/blog/940-SQL-Optimization-Case-Study-JOIN-Clause-vs-IN-Clause.htm
Hope it makes clear to you :)
VulpesRank #55 · 29.2K reputationPosted Nov 30, 2011, 5:02 AM EST
On the face of it, you might expect that 'case 2' would be faster as it should only be necessary to traverse the records in the table once, looking for those to delete.
However, I suspect that there will actually be little or no difference because of the way the query optimizer treats the 'IN' clause.
In addition to the links which Anuja posted, I'd check out this one:
http://stackoverflow.com/questions/714590/most-efficient-fast-t-sql-delete-for-many-rows
Sam HobbsRank #107 · 20.5K reputationPosted Nov 30, 2011, 8:03 AM EST