Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to use Rollback ( update table instead of row)

Author  Topic 

Bram Van den Brande
Starting Member

3 Posts

Posted - 2011-03-17 : 07:33:34
Hey guys,


I'm fairly new to sql stuff and off course i made the noob error.

I updated my whole table instead of one single row

update dbo.tblTeamMembers password
--where FirstName='xxxx'
set password='xxx'

this is what happend. As you see i made my where clause as comment.


Is there any way i can rollbakc what i did? i didn't close my session but i don't use begin transaction as well.

I tried to read up in msdn aout the rollback function but it didn't clearify the use.


Thanks in advance for your help

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-03-17 : 07:53:15
If you didn't issue a BEGIN TRANSACTION command, then you can't roll it back.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-03-17 : 07:54:27
Easiest fix at this point is to restore your latest backup to a different database then update the table from the restored backup.
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-17 : 07:55:30
as per my knowledge you'll need to restore your database restoring most recent backup (plus any transaction log backup if taken since after recent database backup) copy via Tail Log backup method. However restoring to a specific point in time would only work in case if the recovery model of that database is set to Full

Cheers
MIK
Go to Top of Page

Bram Van den Brande
Starting Member

3 Posts

Posted - 2011-03-17 : 08:45:06
Ok thank you ,

I did make a backup of the database, and the rework actually would make it alot faster.

I gues i learned to use begin transaction ;)

thx again
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-03-17 : 08:48:46
Also, it's a good idea to perform a SELECT before and UPDATE to see what will be affected.

in this case

--update dbo.tblTeamMembers
select * from dbo.tblTeamMembers
--where FirstName='xxxx'
set password='xxx'

you'd immediately see that you forgot the where clause before actually updating.
Go to Top of Page
   

- Advertisement -