3 ms·
This is similar to when you run a DELETE statement in SQL. Run it as a select statement first to make sure you have the correct records.
by partisan 11y ago
This is similar to when you run a DELETE statement in SQL. Run it as a select statement first to make sure you have the correct records.
- trcollinson 11y agoIf you absolutely have to run a sql command by hand, it is also a good idea to wrap it in a transaction. Check the delete before committing the transaction, or roll back.
- davismwfl 11y agoTotally agree here. The only exception I have had a few times is when the statement would destroy the transaction log and make the server unresponsive. Working in SQL Server a few years back and having to run some very large deletes instead of truncates (mostly because of a poor design and less than ideal schemas), I found it was BAD to do this and so I had to change my ways. Overall, I like to write SQL scripts that when they go to production are always rerun safe and just overall safe, e.g. Create a transaction, Run expected counts etc then Run the delete, do counts or other queries to insure what happened was what I intended and then commit or rollback. This way my scripts were basically safe in almost all circumstances. Until I hit the crazy DB with huge tables and massively wide tables where my one transaction would trash the transaction log and tempdb and cause SQL to go FU and stop. Ooops. Back to simple select testing it was. Eventually we got the schema's mostly fixed and got a DBA that fixed a lot of stupid on the setup, but still we couldn't run transactions a lot of time because of stupid design choices made way ahead of our involvement.