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
 ROLLBACK

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2006-06-29 : 16:26:42
Hi,

i wanna know something, i inserted some rows of data to a table, but i wanna undo those insertion. How can i do it?

thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-29 : 16:33:36
If the data has been committed, then you can't roll it back now.

Why not just delete the rows?

Do you have transaction log backups? How about a full backup? When was the last backup?


Tara Kizer
aka tduggan
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2006-06-29 : 16:36:59
Not committed and i have no idea about transaction log backups
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-29 : 16:38:58
If it wasn't committed, then you can ROLLBACK TRAN still.

Tara Kizer
aka tduggan
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2006-06-29 : 16:41:09
BEGIN TRANSACTION
ROLLBACK TRAN

like this? i did it like above but inserted rows were still there...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-29 : 16:44:33
BEGIN TRAN

INSERT INTO YourTable
...

ROLLBACK TRAN

The change that you made must be inside the transaction. If it isn't inside the transaction, then the data is already committed. So you'll either have to delete the rows if you know which ones were inserted or restore from a backup.

Tara Kizer
aka tduggan
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-06-29 : 17:43:23
Do this

SELECT @@TRANCOUNT

And tell us what the number is


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-30 : 02:07:42
http://www.sommarskog.se/error-handling-I.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2006-06-30 : 09:17:49
SELECT @@TRANCOUNT

returns 0
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2006-06-30 : 09:19:51
It sounds like you did not use a transaction when you inserted the data, in which case you'll need to remove the lines manually using DELETEs, or restore from a backup.

-------
Moo. :)
Go to Top of Page
   

- Advertisement -