tags:

views:

48

answers:

3

Hello,

I need to update a column in a mysql table. If I do it in two steps as below, is the column "col" updated twice in the disk ?

update table SET col=3*col, col=col+2;

or is it written only once as in :

update table SET col=3*col+2;

Thanks

A: 

Both of the updates will run.

RedFilter
+1  A: 
update table SET col=3*col+2;

this is better. JUST FOR RECORD where table is your tableName and not keyword

Salil
+1  A: 

See: http://dev.mysql.com/doc/refman/5.0/en/update.html

...
Single-table UPDATE assignments are generally evaluated from left to right. For multiple-table updates, there is no guarantee that assignments are carried out in any particular order.
...

I assume the column on disk is only updated once (row written), as it has to validate all assignments / fields in an update, it wouldn't do to write one field and then find out there is a unique key violation.

Wrikken