SQL Server中的并发事务

编程入门 行业动态 更新时间:2024-10-27 23:18:33
本文介绍了SQL Server中的并发事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 如何使用SQL在两个表中进行并发事务? 我有两个表,说tab1和tab2.我想在两个表中插入一些数据.但是,只有一个表永远不会被插入.我想确保要么插入两个表,要么都不插入.如何将事务应用于此任务???? 在此先感谢

Hi there, How to do concurrent transaction in two tables using SQL??? I''ve two tables.Say tab1 and tab2. I wanna insert some data to both the tables. But any one of the table alone never gets inserted. I wanna ensure that, either both tables get inserted or none. How to apply Transaction to this task??? Thanks in advance

推荐答案

执行以下操作 Do the following begin transaction insert into tab1 (col1,col2) values (1,1) insert into tab2 (col11,col22) values (2,2)

提交并保存到两个表:

To commit and save to both tables:

commit transaction

要回滚,两个表中均不保存任何内容:

To rollback and nothing is saved in both tables:

rollback transaction

嘿, aswathy.s.88 我试图收集一些信息让您了解提交"和回滚"条件. BEGIN TRANSACTION为发出该语句的连接启动本地事务.根据当前的事务隔离级别设置,事务将锁定为支持连接发出的Transact-SQL语句而获取的许多资源,直到事务使用COMMIT TRANSACTION或ROLLBACK TRANSACTION语句完成该事务为止. COMMIT TRANSACTION仅在事务引用的所有数据在逻辑上都是正确的时候 和 ROLLBACK TRANSACTION删除从事务开始到保存点的所有数据修改.它还释放了交易所拥有的资源. 参考链接:- COMMIT TRANSACTION(Transact-SQL) [ ^ ] 回滚事务(Transact-SQL) [ ^ ] hey aswathy.s.88 I tried to gather some information for you to let know about Commit and Rollback condition. BEGIN TRANSACTION starts a local transaction for the connection issuing the statement. Depending on the current transaction isolation level settings, many resources acquired to support the Transact-SQL statements issued by the connection are locked by the transaction until it is completed with either a COMMIT TRANSACTION or ROLLBACK TRANSACTION statement COMMIT TRANSACTION only at a point when all data referenced by the transaction is logically correct and ROLLBACK TRANSACTION erases all data modifications made from the start of the transaction or to a savepoint. It also frees resources held by the transaction. Reference Link:- COMMIT TRANSACTION (Transact-SQL)[^] ROLLBACK TRANSACTION (Transact-SQL)[^]

更多推荐

SQL Server中的并发事务

本文发布于:2023-10-16 07:00:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496811.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事务   SQL   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!