Delete Duplicate Rows

If you’ve ever tried to delete two rows that are identical from SSMS, you may come across this little beauty:

To get around this, you have to delete 1 row at a time and use SET ROWCOUNT. So you would do something like

SET ROWCOUNT 1
GO
DELETE FROM users_to_optin where email = 'someone@yahoo.com'

That would delete one record at a time, even if there were multiple instances of ‘someone@yahoo.com’.

After you’re done, make sure you set the rowcount back to 0, which turns the limitation off.

SET ROWCOUNT 0
GO

Check out more about ROWCOUNT.