Three things I've learned over the years ...
First, if you are making updates or deleting data in real time, first write a SELECT query with a WHERE clause that you will use. Make sure it works. Make sure this is correct. Then add the UPDATE / DELETE statement to the well-known WHERE clause.
You will never want to have
DELETE FROM Customers
sits in your query analyzer, waiting for you to write a WHERE clause ... accidentally click execute, and you just killed the Customer table. Unfortunately.
Also, depending on your platform, find out how to quickly back up a table. In SQL Server 2005
SELECT * INTO CustomerBackup200810032034 FROM Customer
will copy each row from the entire Customer table to the new CustomerBackup200810032034 table, which you can delete as soon as you have made your updates and make sure that everything is in order. If the worst happens, it is much easier to recover the missing data from this table than to try to restore the backup of last night from a disk or tape.
Finally, be careful when deleting cascades, getting rid of unnecessary things for you - check the relationships and limitations of keywords before changing.
Dylan Beattie Oct 03 '08 at 19:38 2008-10-03 19:38
source share