请一些人清楚我在SQL服务器中提交和回滚 [英] Please some one clear me one commit and rollback in SQL server

查看:77
本文介绍了请一些人清楚我在SQL服务器中提交和回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道通过回滚我们将恢复删除记录,如果提交我们无法获取删除记录,但它的工作如何实现它的事情我想清除我搜索它多次但我没有得到一个正确和明确回答请帮帮我..



假设我有一张员工表,我删除了一条记录,如



从员工中删除姓名='Riya'



删除后我想回滚它请建议我



谢谢



我尝试过:



从Employee中开始TRAN DELETE select * from Employee ROLLBACK select * from Employee

i know about through rollback we will recover delete record and if commit we cant get delete record but how its work how to implement it thing thing i want to clear i search for it many times but i am not get a proper and clear answer please help me on it..

suppose i have a Employee table and i delete a record like

delete from Employee where Name='Riya'

after delete i want to rollback it please suggest me on it

Thank You

What I have tried:

begin TRAN DELETE from Employee select * from Employee ROLLBACK select * from Employee

推荐答案

你已经关闭了。您只需要将WHERE子句添加到DELETE语句。如果只是运行begin tran然后删除,你会注意到Riya不存在,回滚并再次选择表格,Riya应该出现。

You're close. You just needed to add the WHERE clause to the DELETE statement. If just run the begin tran and then the delete, you'll notice Riya is not there, roll it back and select the table again, Riya should appear.
BEGIN TRAN
DELETE from Employee WHERE [Name] = 'Riya'
ROLLBACK
select * from Employee 


如果出现任何问题任何分组语句,都需要中止所有更改。逆转更改的过程在SQL Server术语中称为回滚。如果一切事务中的所有语句都按顺序排列,则所有更改将一起记录在数据库中。在SQL Server术语中,我们说这些更改已提交到数据库。

请参阅下面的简单查询摘要

If anything goes wrong with any of the grouped statements, all changes need to be aborted. The process of reversing changes is called rollback in SQL Server terminology. If everything is in order with all statements within a single transaction, all changes are recorded together in the database. In SQL Server terminology, we say that these changes are committed to the database.
see below simple query snippet
BEGIN TRANSACTION trans
BEGIN TRY
DELETE from Employee WHERE [Name] = 'Riya'
 BEGIN COMMIT TRANSACTION trans
 END
END TRY
BEGIN CATCH
 print 'Error Occured'
 BEGIN ROLLBACK TRANSACTION trans 
 END
END CATCH 



见上面的代码片段我们在sql中放了try..catch,如果在执行DELETE语句时发生任何错误然后事务获取rollbacked


see above snippet in which we have put try..catch in sql, if any error occurred when executing DELETE statement then transaction get rollbacked


你好,



检查这个....





提交和回滚SQL Server中的命令 [ ^ ]





希望这会对你有所帮助。



干杯
Hi,

Check this....


Commit and Rollback Commands in SQL Server[^]


Hope this will help you.

Cheers


这篇关于请一些人清楚我在SQL服务器中提交和回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆