Is this the most efficient way to delete from DeletedProducts table where there are not references found in the ProductFileInfo table?
Sample:
DELETE FROM DeletedProducts
WHERE ProductId NOT IN SELECT DISTINCT ProductID FROM ProductFileInfo
Or is NOT EXIST a better way to perform this.
Note: ProductFileInfo has over 20 Million records in it.
SQL Server 2005 Standard is what I am using.
Thanks
NOT IN and NOT EXISTS will probably produce the same plan. How many rows are you going to delete? If it is a lot I would do batches of 5K or 10K this way you won’t fill your LOG with one big transaction and then if it fails for whatever reason it needs to do a big rollback
for example
in order for GO N to work you need SSMS and service pack 2 (IIRC) but of course you can also write a while loop..
while @@rowcount > 0…….