Transaction Processing

ColdFusion provides support for database transaction processing using the cftransaction tag. The cftransaction tag lets you treat all query operations with the <cftransaction> and </cftransaction> tags as a single transaction. Changes to the database aren’t committed until all queries in the transaction have executed successfully. In the event a query within the transaction fails, all previous queries are automatically rolled back. The exception to this occurs when the database itself is changed, as in the case when a table or column is created or deleted.

The cftransaction tag accepts two optional attributes for controlling how transactions are processed, action and isolation:


Specifies the transaction action to take. Valid options include:

Begin (default)

Specifies the beginning of the block of code to execute


Commits a pending transaction


Rolls back a pending transaction


Specifies the ODBC lock type to use for the transaction. The following ODBC lock types are supported: Read_Uncommitted, Read_Committed, Repeatable_Read, and Serializable.

Note that not all databases and/or database drivers support isolation levels. Many support only a subset of those listed. Refer to your particular database/driver’s documentation for more information on the isolation levels supported.

Example 11-26 shows how to use the cftransaction tag with two queries that delete records from different tables within the same data source. You need ...

Get Programming ColdFusion MX, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.