I made a huge mistake, I executed this query:
update Contact set ContaPassword = '7FD736A3070CB9766'
I forgot the WHERE
clause, so this way it updated the password for all users. :(
Is there a way I can recover the data before this query?
Once SQL Server commits a transaction, you cannot run the ROLLBACK statement. Each rollback statement should have an association with the BEGIN Transaction statement.
A rollback command can only be executed if the user has not performed the COMMIT command on the current transaction or statement.
You cannot ROLLBACK an operation without a transaction. You could probably use implicit transactions, but you still need to call COMMIT or ROLLBACK explicitly. However, for better control, it's better to wrap the statement(s) in a BEGIN TRANSACTION... COMMIT / ROLLBACK block anyway.
If you neither commit nor rollback the transaction, the transaction will continue to exist indefinitely.
You cannot undo the change if you ran it outside of a BEGIN TRANSACTION / ROLLBACK. This is why I begin any sort of production data update with:
BEGIN TRANSACTION
-- report the bad or undesired data condition before-hand
SELECT ...
-- change the data
INSERT/UPDATE/DELETE ...
-- ensure we changed a reasonable number of records; may not be accurate if table has triggers
SELECT @@ROWCOUNT
-- get the data condition afterwards and be sure it looks good.
SELECT ...
-- always start with this enabled first
ROLLBACK
-- don't do this until you are very sure the change looks good
-- COMMIT
Martin Smith pointed out this excellent post by Brent Ozar on dba.stackexchange.com on this topic. In full recovery mode, it is possible to examine the log files to see what changed.
Also, as Oded pointed out, if you have backups, it is not hard to get back to the original data. You can restore the backup somewhere and copy the original data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With