Nothing wakes you up faster in the morning than a cup of coffee or running a SQL Update without a Where clause.
One thing I’ve gotten in the habit of using is a simple script to update or delete SQL data. It’s kept me out of trouble more often than not.
- Select with the where clause.
- Perform the update (with the same where clause).
- Only commit the transaction if the expected number of rows are updated.
- Select again to visually compare the results.
select col, * from table where BEGIN TRANSACTION T1 DECLARE @rc int update set where SET @rc = @@ROWCOUNT IF @rc <> ROLLBACK TRANSACTION ELSE COMMIT TRANSACTION select col, * from table where