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

ALTER [IGNORE] TABLE t action, …: a request to change the structure of a table.

Mirrors PT_alter_table_stmt and PT_alter_table_standalone_stmt. Rule: MYSQL-ALTER-TABLE-001. The actions are kept in the order written, modifiers (ALGORITHM, LOCK, VALIDATION) among them; a standalone action (a partition or tablespace operation) is the last one and only modifiers precede it; PARTITION BY and REMOVE PARTITIONING are the last one and follow the others without a comma. The table resolves by MYSQL-CHANGE-TARGET-001; a declared view is refused (MYSQL-RELATION-KIND-001). The statement node is the relation occurrence the expressions of the actions see: its relation fact holds the resolution of the table and the row shape of the visible columns the table has after the column actions; its invisible columns are found by name only (MYSQL-COLUMN-CHANGES-001), which also reports a changed, dropped, renamed or altered column the completely known table does not have and a column name the table would have twice. The statement changes no declaration and provides none. IGNORE exists in 5.6 only. Source: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html, https://dev.mysql.com/doc/refman/5.6/en/alter-table.html. Status: Implemented.

Reading the actions of a table changedoctest
$semantics = new \SqlSemantics\Platform\MySql\Semantics();
    $table = $semantics->analyze('CREATE TABLE t (a INT)');
    $semantics->analyze('ALTER TABLE t DROP COLUMN b, ALGORITHM = INPLACE', [$table]) // throws \SqlSemantics\Platform\MySql\Model\Diagnostic\SemanticException: Column b does not exist in the table.

Properties§

public list<AlterCommand> $commands
public QualifiedName $table
public bool $ignore = false

Methods§

public function __construct(
    public QualifiedName $table,
    list<AlterCommand> $commands,
    public bool $ignore = false,
)

Parameters

$tableQualifiedNameThe table with its optional database
$commandslist<AlterCommand>The actions in the order written
$ignoreboolWhether IGNORE is written (5.6)
Calls 4
public function deriveStatement(Derivation $derivation): void

Derives the table and every action in the scope of the table as the statement leaves it.

Parameters

$derivationDerivation
Calls 12
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Resolves the table and answers the row shape of its visible columns after the column actions.

Parameters

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

Writes the request.

Parameters

$outOutput
Calls 6

Test cases 4§

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 3

Relations§

Instantiated in 2
Type declarations 1