SQL事务 [英] SQL Transaction

查看:70
本文介绍了SQL事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与SQL事务有关的问题,我在数据库中有4个表,并且第一个表的主键应作为所有三个表中的属性出现,这里我使用SQL事务在其中插入数据所有四个表.我已经在第一个表中插入了数据,并使用@@ identity获取了最后一个插入值(主键值),现在我试图将所有三个表中的数据与第一个表的主键值一起插入,但是在插入时想要的表中的数据存在错误……现在我要回滚第一张表和第二张表中的所有插入数据.为此,我已将其回滚到缓存块中……问题就在这里,但尚未执行commit语句,因此我想知道是物理插入还是逻辑上插入了第一和第二个表中的数据,如果物理上然后回滚操作在内部删除了数据,也删除日志...是真的吗?如果从逻辑上讲,那么在这种情况下的内部流程将是什么..???数据将以逻辑方式存储的地方... ??

I have one question rlated to SQL-Transaction, I have 4 tables in the database and primary key of first table should aapear as an attribute in all three tables, here I''m using SQL-transaction to insert the data in all four tables. I have inserted data in first table and taken the last inserted value (primary key value) using @@identity and now I''m trying to insert the data in all three tables along with first table''s primary key value but while inserting the data in thired table there is error has accured...now I want to rollback all inserted data from first and second tables. for that I have rollback it in cache block...the question is here,yet commit statement has not executed so I want to know whether data in first and second tables physically inserted or logically , if physically then rollback action internally delete the data and delete the log as well...is it true?? and if logically then what will be the internal process in that case..??.where data will stored logically...??

推荐答案

看看这些链接:
回滚事务(Transact-SQL) [ SQL交易语句 [ ^ ]
SQL Server中的TRY ... CATCH-更简单的回滚方式 [
Have a look at these links:
ROLLBACK TRANSACTION (Transact-SQL)[^]
SQL-Transaction Statements[^]
TRY...CATCH in SQL Server - Easier way to Rollback[^]


这篇关于SQL事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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