2023年8月3日发(作者:)

mysqlupdate顺序,MYSQL的UPDATE中SET的执⾏顺序在写UPDATE语句时,发现set多个字段,并且字段有关联关系时,情况会不同:第⼀种情况如下,num可以根据count更新之后的数据来更新,⽹上搜索“update执⾏顺序”,也可以找到很多类似的⽰例:update _table set count = count + 1, num = count/2 where id = 1;第⼆种情况,是写的⽐较复杂的连表更新,排在后⾯的字段⽆法根据之前已经更新的字段来更新,查看stackoverflow 和 mysql的官⽅⽂档,发现描述如下,结论就是,单表的话mysql会有顺序,后执⾏的会⽤先执⾏的数据来更新,但是多表的话就不再有该顺序:/doc/refman/5.6/en/ you access a column from the table to be updated in an expression, UPDATE uses the current value of the column. Forexample, the following statement sets col1 to one more than its current value:UPDATE t1 SET col1 = col1 + 1;The second assignment in the following statement sets col2 to the current (updated) col1 value, not the original col1 result is that col1 and col2 have the same value. This behavior differs from standard t1 SET col1 = col1 + 1, col2 = col1;Single-table UPDATE assignments are generally evaluated from left to multiple-table updates, there is no guarantee that assignments are carried out in any particular order.

2023年8月3日发(作者:)

mysqlupdate顺序,MYSQL的UPDATE中SET的执⾏顺序在写UPDATE语句时,发现set多个字段,并且字段有关联关系时,情况会不同:第⼀种情况如下,num可以根据count更新之后的数据来更新,⽹上搜索“update执⾏顺序”,也可以找到很多类似的⽰例:update _table set count = count + 1, num = count/2 where id = 1;第⼆种情况,是写的⽐较复杂的连表更新,排在后⾯的字段⽆法根据之前已经更新的字段来更新,查看stackoverflow 和 mysql的官⽅⽂档,发现描述如下,结论就是,单表的话mysql会有顺序,后执⾏的会⽤先执⾏的数据来更新,但是多表的话就不再有该顺序:/doc/refman/5.6/en/ you access a column from the table to be updated in an expression, UPDATE uses the current value of the column. Forexample, the following statement sets col1 to one more than its current value:UPDATE t1 SET col1 = col1 + 1;The second assignment in the following statement sets col2 to the current (updated) col1 value, not the original col1 result is that col1 and col2 have the same value. This behavior differs from standard t1 SET col1 = col1 + 1, col2 = col1;Single-table UPDATE assignments are generally evaluated from left to multiple-table updates, there is no guarantee that assignments are carried out in any particular order.