事务内部的select语句与外部的select语句之间是否有区别 [英] is there a difference between a select statement inside a transaction and one that is outside of it

查看:274
本文介绍了事务内部的select语句与外部的select语句之间是否有区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认的READ COMMITTED隔离级别是否以某种方式使select语句在事务内的行为不同于不在事务内的select语句?

Does the default READ COMMITTED isolation level somehow makes the select statement act different inside of a transaction than one that is not in a transaction?

我正在使用MSSQL.

I am using MSSQL.

推荐答案

是的,事务内部的人可以看到那个事务中其他先前的Insert/Update/delete语句所做的更改;事务外的Select语句不能.

Yes, the one inside the transaction can see changes made by other previous Insert/Update/delete statements in that transaction; a Select statement outside the transaction cannot.

如果您要问的是隔离级别的用途,那么请了解所有Select语句(嘿,所有类型的所有语句)- .显式处于事务中的事务和独立于事务中的事务之间的唯一区别是,独立的事务在执行事务之前立即开始其事务,并在执行之后立即提交或回滚;

If all you are asking about is what the Isolation Level does, then understand that all Select statements (hey, all statements of any kind) - are in a transaction. The only difference between one that is explicitly in a transaction and one that is standing on its own is that the one that is standing alone starts its transaction immediately before it executes it, and commits or roll back immediately after it executes;

而一个事务中显式的 可以(因为它有一个Begin Transaction语句)可以在同一事务中有其他语句(插入/更新/删除,无论如何),在此之前或在该Select语句之后.

whereas the one that is explicitly in a transaction can (because it has a Begin Transaction statement) can have other statements (inserts/updates/deletes, whatever) occurring within that same transaction, either before or after that Select statement.

因此,无论将隔离级别设置为什么,两个选择(在显式事务内部或外部)都将处于以该隔离级别运行的事务中.

So whatever the isolation level is set to, both selects (inside or outside an explicit transaction) will nevertheless be in a transaction which is operating at that isolation level.

添加: 以下内容适用于SQL Server,但所有数据库必须以相同的方式工作.在SQL Server中,查询处理器始终处于三种事务模式之一,即 AutoCommit Implicit Explicit .

Addition: The following is for SQL Server, but all databases MUST work in the same way. In SQL Server the Query Processor is always in one of 3 Transaction Modes, AutoCommit, Implicit, or Explicit.

  • 自动提交是SQL Server数据库引擎的默认事务管理模式. ..每个Transact-SQL语句在完成时都将提交或回退. ... 如果语句成功完成,则将其提交;如果遇到任何错误,它将回滚.这是默认设置,它是注释中@Alex问题的答案.

  • AutoCommit is the default transaction management mode of the SQL Server Database Engine. .. Every Transact-SQL statement is committed or rolled back when it completes. ... If a statement completes successfully, it is committed; if it encounters any error, it is rolled back. This is the default, and is the answer to @Alex's question in the comments.

隐式事务模式,"... SQL Server数据库引擎会在当前事务被提交或回滚后自动启动新事务.您无需进行任何描述事务开始;您仅提交或回滚每个事务.隐式事务模式会生成连续的事务链."请注意,斜体代码段适用于每个事务,无论是单语句事务还是多语句事务.

In Implicit Transaction mode, "... the SQL Server Database Engine automatically starts a new transaction after the current transaction is committed or rolled back. You do nothing to delineate the start of a transaction; you only commit or roll back each transaction. Implicit transaction mode generates a continuous chain of transactions. ..." Note that the italicized snippet is for each transaction, whether it be a single or multiple statement transaction.

引擎放置在

The engine is placed in Explicit Transaction mode when you explicitly initiate a transaction with BEGIN TRANSACTION Statement. Then, every statement is executed within that transaction until you explicitly terminate the transaction (with COMMIT or ROLLBACK) or if a failure occurs that causes the engine to terminate and Rollback.

这篇关于事务内部的select语句与外部的select语句之间是否有区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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