在一次查询中更新多个 MySQL 表时,是否始终保证分配顺序?

When updating multiple MySQL tables in one query, is assignment order always guaranteed?

考虑在一个查询中更新表 A 和 B 的示例,这样 A.Column1 设置为 B.Column2(值 "DEF")然后 B.Column2 设置为值 "XYZ." 分配顺序是否始终得到保证,以便 A.Column1 的值为 "DEF" 而不是 "XYZ"?

SQL 示例:

UPDATE TableA a
JOIN TableB b ON b.Column0 = a.Column0
SET
    a.Column1 = b.Column2, -- Original value: "DEF"
    b.Column2 = 'XYZ'
WHERE a.Column0 = 123;

SELECT Column1 FROM TableA WHERE Column0 = 123; -- DEF or XYZ?

值得注意的是 the documentation on UPDATE 对此很清楚:

The second assignment in the following statement sets col2 to the current (updated) col1 value, not the original col1 value. The result is that col1 and col2 have the same value. This behavior differs from standard SQL.

令人惊讶的是,是的,秩序确实很重要并且受到尊重。不过,这似乎是一件古怪的事情 MySQL,所以我不会过分依赖它,因为切换到另一个 RDBMS 会在它停止工作时造成相当大的混乱。