I’m running into some scenarios where I must either delete or modify a record by hand in our production database. This is usually where the application doesn’t work the way it was intended to.
How can I delete or update these records without accidentally deleting or modifying all records in the table I’m working with?
Are transactions a suitable way of achieving this?
I’m using SQL Server Management Studio if that helps.
Yes. Transactions are ALWAYS a good idea.
Check out the OUTPUT Clause. Begin a transaction, execute your update or delete statement with the output clause in place, verify results, then commit the transaction.
I do this:
I run that, take time to look at the results. Then change the last statement to
COMMIT TRANSACTIONwhen I’m satisfied and run it again.That said, I’d do nearly anything I could to avoid doing this. It scares me. If you find yourself doing this more than once perhaps, add something to your application which provides this admistration function (or fix the bug that you’re cleaning up).