final class CheckConstraint
    implements TableElement, ColumnAttribute
    uses Snapshot
Public API: explicitly declared with @visibility public.

A CHECK constraint, as a table element or as a column attribute.

Rule: MYSQL-CHECK-CONSTRAINT-001. The condition sees the columns of the table (MYSQL-DEFINITION-SCOPE-001). MySQL 8.0.16 and later enforce the constraint unless NOT ENFORCED is written; earlier releases parse and ignore it. A table element carries its ENFORCED clause; a column attribute has none of its own, because the server reads ENFORCED after it as a separate attribute (EnforcementAttribute). Source: https://dev.mysql.com/doc/refman/8.4/en/create-table-check-constraints.html. Status: Implemented.

Reading a check constraintdoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TABLE t (a INT, CONSTRAINT positive CHECK (a > 0) NOT ENFORCED)');
    [$create->statement->elements[1]->name->name->column->value, $create->statement->elements[1]->enforced] // => ['positive', false]

Properties§

public Scalar $condition
public ConstraintName|null $name = null
public bool|null $enforced = null

Methods§

public function __construct(
    public Scalar $condition,
    public ConstraintName|null $name = null,
    public bool|null $enforced = null,
)

Parameters

$conditionScalarThe condition every row must not make false
$nameConstraintName|nullThe CONSTRAINT clause, when written
$enforcedbool|nullWhether ENFORCED (true) or NOT ENFORCED (false) is written after a table constraint; null when absent
public function deriveElement(Derivation $derivation, Environment $scope): void

Derives the condition inside the table definition.

Parameters

$derivationDerivation
$scopeEnvironment
Test cases 1
Calls 1
public function deriveAttribute(Derivation $derivation, Environment $scope): void

Derives the condition inside the table definition.

Parameters

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

Writes the constraint name, the condition and the enforcement.

Parameters

$outOutput
Calls 2

Test cases 5§

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

Dedicated tests 1
Other tests reaching this symbol 4

Relations§

Instantiated in 4
Type declarations 2