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

A request to create an empty table with the definition of another table: CREATE TABLE ... LIKE.

Rule: MYSQL-CREATE-TABLE-LIKE-001. The source table is a table use: the statement node records its resolution as a target; a declared view is refused (MYSQL-RELATION-KIND-001). The statement provides one declaration with new columns of the same names, types and NULL facts as the source (MYSQL-TABLE-DECLARATION-001); an undeclared or missing source leaves it empty and incomplete. LIKE t and (LIKE t) are the same request. Source: https://dev.mysql.com/doc/refman/8.4/en/create-table-like.html. Status: Implemented.

Copying the columns of a declared tabledoctest
$semantics = new \SqlSemantics\Platform\MySql\Semantics();
    $source = $semantics->analyze('CREATE TABLE s (a INT NOT NULL)');
    $copy = $semantics->analyze('CREATE TABLE c LIKE s', [$source])->declarations()[0];
    [$copy->name->name->value, $copy->columns[0]->name->value, $copy->columns[0] === $source->declarations()[0]->columns[0]] // => ['c', 'a', false]

Properties§

public QualifiedName $source
public int $temporaryWords = 0
public bool $ifNotExists = false

Methods§

public function __construct(
    public QualifiedName $name,
    public QualifiedName $source,
    public int $temporaryWords = 0,
    public bool $ifNotExists = false,
)

Parameters

$nameQualifiedNameThe table name
$sourceQualifiedNameThe table whose definition is copied
$temporaryWordsintHow many times TEMPORARY is written; MySQL 8.0 and later accept it once
$ifNotExistsboolWhether IF NOT EXISTS is written
Calls 1
public function deriveStatement(Derivation $derivation): void

Resolves the source table and provides the copied declaration.

Parameters

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

Writes the definition.

Parameters

$outOutput
Calls 4

Test cases 2§

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 1

Relations§

Instantiated in 4