I’ve been doing a lot of data maintenance work at my current job. It seems every now and then some bad data causes something to go wrong in the system. Attempting to correct these issues by fixing the data I have also accidentally caused more problems. I would like to share some data maintenance script tips that you should follow before ever attempting to run a script.
- Test Your Script – I can’t stress this enough. You can never test enough. Make sure your logic is correct. Read the script and read it again. Remember it just takes one bad piece of logic to mess up the data even more.
- Check Your Select - If your going to be updating data from data in a temp table testing your selects is by fat the best way to see the records that will be updated. Now if these records are what you would expect you’ll have no problems. If your logic is incomplete you may have made your problems worse. If you’re lucky and you’re logic wasn’t complete you may need to run another script to complete the data fix.
- Keep A List Of All Rows That Will Be Modified If Possible - This should be one of the most important things you do before having your script executed. Keeping a list of all rows that your script will modify is a extra precaution that should always be taken. It can serve as a verification that the script touches all data that needs to be modified. Also if you need to restore the data back to the previous state (depending on how complex the logic is) this will help by having a record of what was changed.
These are the data maintenance script tips that I have learned from past experience. I hope that the tips above will help learn from my success and failures of doing way too much data maintenance.