SiteKickr Web Development

MySQL Bulk Update with ColdFusion

The example below demonstrates the use of the MySQL CASE statement to cleverly construct a bulk update statement. A huge performance boost over performing individual update statements, especially if you have a large number of them to execute.

<cfquery>
    UPDATE mytable
    SET position =
        CASE
            <cfloop from="1" to="#length#" index="i">
            WHEN element_id = #Val(ListGetAt(arguments.positions, i), 2)# THEN #i#
            </cfloop>
        END
</cfquery>