简体   繁体   English

使用开始事务设置var mysql

[英]set var mysql with start transaction

i don't familiar at database, That is my test syntax: 我对数据库不熟悉,这是我的测试语法:

START TRANSACTION ;
SET @VAR = (SELECT `some ID` FROM `some table` ORDER BY `some ID` DESC LIMIT 1);
SELECT @VAR;
COMMIT;
SELECT @VAR;

i think is result is first select is null (because before commit) and second select is have value, and in my test first and second select have value, why? 我认为结果是第一次选择为空(因为在提交之前)并且第二次选择具有值,并且在我的测试中,第一和第二次选择具有值,为什么? and how to fix my syntax? 以及如何修复我的语法?

You seem confused. 你似乎很困惑。 First, changes made within a transaction are visible within the same transaction. 首先,在一个事务中进行的更改在同一事务中可见。 Second, transactions are about changes to the database , not changes to the session . 其次,事务是关于数据库的更改,而不是关于会话的更改。 After all, the database is ACID-compliant (or not), not the variables in a session. 毕竟,数据库是否符合ACID标准,而不是会话中的变量。

The first print prints the value present during the transaction. 第一个print打印交易期间存在的值。 Changes within a transaction are visible -- in the transaction. 交易中的更改是可见的-在交易中。 This is true for changes on tables, as well. 对于表的更改也是如此。 If you insert a row in a table and -- in the same transaction -- look for the row, then you will see it. 如果您在表格中插入一行,并且-在同一事务中-查找该行,那么您将看到它。

You should not see the row in another session. 您不应在其他会话中看到该行。 You won't see it elsewhere, until the changes are committed. 在提交更改之前,您不会在其他地方看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM