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
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Rollback in sql server 2008

Author  Topic 

rohitmathur11
Yak Posting Veteran

77 Posts

Posted - 2009-12-15 : 01:51:02
Hi,
i need to update or delete data from database .
I want rollback option ..if any thing goes wrong..
i tried

declare @abc varchar(10) = 'xx';
begin tran @abc
insert into A_EMP values (2,1)
rollback tran @abc

but it is not working ..then how to use rollback .....?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-15 : 01:53:42
begin tran
insert into A_EMP values (2,1)
rollback tran

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

rohitmathur11
Yak Posting Veteran

77 Posts

Posted - 2009-12-15 : 02:04:39
Hi,

thanks for reply...

i tryed this

brgin tran abc

update ....

rollback trn abc

it is also working ...

thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-15 : 02:06:01
Yes that would work too. Your dynamic way requires dynamic SQL, but I can't imagine why you'd want to do that.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

rohitmathur11
Yak Posting Veteran

77 Posts

Posted - 2009-12-16 : 00:01:35
I can\will use both ..i was just telling the other way..

any way ...thanks a lot for helping me ...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-16 : 00:04:41
Well you shouldn't use the dynamic SQL approach for performance and security reasons.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -