final class CreateTrigger
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

CREATE TRIGGER: a statement that runs for each row an INSERT, UPDATE or DELETE changes in a table.

The statement is structured as a request: it declares nothing to a context. The facts follow MYSQL-TRIGGER-001. Source: https://dev.mysql.com/doc/refman/8.4/en/create-trigger.html.

Reading a trigger definitiondoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TRIGGER tr BEFORE UPDATE ON t FOR EACH ROW SET @changed = 1');
    [$create->statement->time->value, $create->statement->event->value, $create->statement->table->name->name->value] // => ['BEFORE', 'UPDATE', 't']

Properties§

public TriggerTime $time
public TriggerEvent $event
public TriggerTable $table
public TriggerOrder|null $order = null
public Account|null $definer = null
public bool $ifNotExists = false

Methods§

public function __construct(
    public QualifiedName $name,
    public TriggerTime $time,
    public TriggerEvent $event,
    public TriggerTable $table,
    Node $body,
    public TriggerOrder|null $order = null,
    public Account|null $definer = null,
    public bool $ifNotExists = false,
)

Parameters

$nameQualifiedNameThe trigger name with its optional database
$timeTriggerTimeWhether the trigger runs before or after the row change
$eventTriggerEventThe kind of row change that activates the trigger
$tableTriggerTableThe table the trigger belongs to
$bodyNodeThe statement the trigger runs: a program statement or an SQL statement
$orderTriggerOrder|nullThe FOLLOWS or PRECEDES clause (MySQL 5.7 and later)
$definerAccount|nullThe DEFINER clause, when written
$ifNotExistsboolWhether IF NOT EXISTS is written (MySQL 8.0.29 and later)

Throws

InvalidConstruction When the body is of another class
Calls 3
public function deriveStatement(Derivation $derivation): void

Derives the table and the body, in which NEW and OLD denote the row of the table.

Parameters

$derivationDerivation
Calls 2
public function render(Output $out): void

Writes the statement.

Parameters

$outOutput
Calls 3

Test cases 15§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 3
Other tests reaching this symbol 12

Relations§

Instantiated in 1
Type checks 1
Type declarations 1