User Guide
cftransaction 343
cftransaction
Description
Instructs the database management system to treat multiple database operations as a single
transaction. Provides database commit and rollback processing.
Category
Database manipulation tags
Syntax
<cftransaction
action = "begin" or "commit" or "rollback"
isolation = "read_uncommitted" or "read_committed" or
"repeatable_read" >
</cftransaction>
See also
cfinsert, cfprocparam, cfprocresult, cfquery, cfqueryparam, cfstoredproc,
cfupdate
Attributes
Usage
Within a transaction block, you can do the following:
• Commit a database transaction by nesting the <cftransaction action = "commit"/> tag
within the block
• Roll back a transaction by nesting the <cftransaction action = "rollback"/> tag within
the block
(In these examples, the slash is alternate syntax that is the equivalent of an end tag.)
Within a transaction block, you can write queries to more than one database, but you must
commit or rollback a transaction to one database before writing a query to another. Using CFML
error handling, you control whether each transaction is committed, based on the success or failure
of the database query. To control how the database engine performs locking during the
transaction, use the
isolation attribute.
Example
<p>CFTRANSACTION can be used to group multiple queries that use CFQUERY
into one business event. Changes to data that is requested by the queries
are not committed to the datasource until all actions within the transaction
block have executed successfully.
<p>This a view-only example.
<!---
Attribute Req/Opt Default Description
action Optional begin • begin: the start of the block of code to execute.
• commit: commits a pending transaction
• rollback: rolls back a pending transaction
isolation Optional ODBC lock type.
• read_uncommitted
• read_committed
• repeatable_read
• serializable