Suppose that I have a table with 10000000 record. What is difference between this two solution?
-
delete data like :
DELETE FROM MyTable -
delete all of data with a application row by row :
DELETE FROM MyTable WHERE ID = @SelectedID
Is the first solution has best performance?
what is the impact on log and performance?
If you have that many records in your table and you want to delete them all, you should consider
truncate <table>instead ofdelete from <table>. It will be much faster, but be aware that it cannot activate a trigger.See for more details (this case sql server 2000):
http://msdn.microsoft.com/en-us/library/aa260621%28SQL.80%29.aspx
Deleting the table within the application row by row will end up in long long time, as your dbms can not optimize anything, as it doesn’t know in advance, that you are going to delete everything.