It is usually created by calling [[Connection::beginTransaction()]].
The following code is a typical example of using transactions (note that some
DBMS may not support transactions):
php
$transaction = $connection->beginTransaction();
try {
$connection->createCommand($sql1)->execute();
$connection->createCommand($sql2)->execute();
.... other SQL executions
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}