classCreateTableLike
final class CreateTableLike
implements Statement
uses Snapshot
@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.
$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 $namepublic QualifiedName $sourcepublic int $temporaryWords = 0public bool $ifNotExists = falseMethods§
public function __construct(
public QualifiedName $name,
public QualifiedName $source,
public int $temporaryWords = 0,
public bool $ifNotExists = false,
)Parameters
$name | QualifiedName | The table name |
$source | QualifiedName | The table whose definition is copied |
$temporaryWords | int | How many times TEMPORARY is written; MySQL 8.0 and later accept it once |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
Calls 1
- static-call Check::input() line 55
public function deriveStatement(Derivation $derivation): voidResolves the source table and provides the copied declaration.
Parameters
$derivation | Derivation |
Calls 9
- method-call Derivation::target() line 64
- method-call TableTargets::existing() line 64
- new TableTargets line 64
- method-call RelationKinds::require() line 65
- new RelationKinds line 65
- class-const RelationKind::BaseTable() line 65
- method-call Derivation::declare() line 66
- method-call TableDeclaration::like() line 66
- new TableDeclaration line 66
public function render(Output $out): voidWrites the definition.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 74
- method-call Output::name() line 87
- class-const NameUse::Qualifier() line 87
- class-const NameUse::Relation() line 89
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
CreateTableLikeTestcalls
Other tests reaching this symbol 1
Relations§
Instantiated in 4
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\CreateTableRule::legacy() packages/sql-semantics-mysql/src/Lowering/TableDefinition/CreateTableRule.php:67
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\CreateTableRule::legacy() packages/sql-semantics-mysql/src/Lowering/TableDefinition/CreateTableRule.php:68
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\CreateTableRule::modern() packages/sql-semantics-mysql/src/Lowering/TableDefinition/CreateTableRule.php:165
- new SqlSemantics\Platform\MySql\Lowering\TableDefinition\CreateTableRule::modern() packages/sql-semantics-mysql/src/Lowering/TableDefinition/CreateTableRule.php:166