Interface Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
| Implemented by | Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder, Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
|---|
Defines methods for building SQL statements for DDL (data definition language).
Public Methods
Method Details
Creates an SQL command for adding a check constraint to an existing table.
| public abstract string addCheck ( string $table, string $name, string $expression ) | ||
| $table | string |
The table to add the check constraint to. |
| $name | string |
The name of the check constraint. |
| $expression | string |
The SQL of the |
| return | string |
The SQL statement for adding a check constraint to an existing table. Note: The method will quote the |
|---|---|---|
public function addCheck(string $table, string $name, string $expression): string;
Builds an SQL statement for adding a new DB column.
| public abstract string addColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type ) | ||
| $table | string |
The table to add the new column will to. |
| $column | string |
The name of the new column. |
| $type | Yiisoft\Db\Schema\Column\ColumnInterface|string |
The column type which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions
into SQL representation. For example, it will convert The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. |
| return | string |
The SQL statement for adding a new column. Note: The method will quote the |
|---|---|---|
public function addColumn(string $table, string $column, ColumnInterface|string $type): string;
Builds an SQL command for adding comment to column.
| public abstract string addCommentOnColumn ( string $table, string $column, string $comment ) | ||
| $table | string |
The table whose column to be comment. |
| $column | string |
The name of the column to comment. |
| $comment | string |
The text of the comment to add. |
| return | string |
The SQL statement for adding comment on column. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
public function addCommentOnColumn(string $table, string $column, string $comment): string;
Builds an SQL command for adding comment to the table.
| public abstract string addCommentOnTable ( string $table, string $comment ) | ||
| $table | string |
The table whose column is to comment. |
| $comment | string |
The text of the comment to add. |
| return | string |
The SQL statement for adding comment on the table. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
public function addCommentOnTable(string $table, string $comment): string;
Creates an SQL command for adding a default value constraint to an existing table.
| public abstract string addDefaultValue ( string $table, string $name, string $column, mixed $value ) | ||
| $table | string |
The table toi add the default value constraint to. |
| $name | string |
The name of the default value constraint. |
| $column | string |
The name of the column to add constraint on. |
| $value | mixed |
The default value to set for the column. |
| return | string |
The SQL statement for adding a default value constraint to an existing table. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function addDefaultValue(string $table, string $name, string $column, mixed $value): string;
Builds an SQL statement for adding a foreign key constraint to an existing table.
The method will quote the name, table, referenceTable parameters before using them in the generated SQL.
| public abstract string addForeignKey ( string $table, string $name, array|string $columns, string $referenceTable, array|string $referenceColumns, string|null $delete = null, string|null $update = null ) | ||
| $table | string |
The table to add the foreign key constraint will to. |
| $name | string |
The name of the foreign key constraint. |
| $columns | array|string |
The name of the column to add the constraint will on. If there are many columns, separate them with commas or use an array to represent them. |
| $referenceTable | string |
The table that the foreign key references to. |
| $referenceColumns | array|string |
The name of the column that the foreign key references to. If there are many columns, separate them with commas or use an array to represent them. |
| $delete | string|null |
The |
| $update | string|null |
The |
| return | string |
The SQL statement for adding a foreign key constraint to an existing table. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
public function addForeignKey(
string $table,
string $name,
array|string $columns,
string $referenceTable,
array|string $referenceColumns,
?string $delete = null,
?string $update = null,
): string;
Builds an SQL statement for adding a primary key constraint to an existing table.
| public abstract string addPrimaryKey ( string $table, string $name, string|string[] $columns ) | ||
| $table | string |
The table to add the primary key constraint will to. |
| $name | string |
The name of the primary key constraint. |
| $columns | string|string[] |
Comma separated string or array of columns that the primary key will consist of. |
| return | string |
The SQL statement for adding a primary key constraint to an existing table. Note: The method will quote the |
|---|---|---|
public function addPrimaryKey(string $table, string $name, array|string $columns): string;
Creates an SQL command for adding a unique constraint to an existing table.
| public abstract string addUnique ( string $table, string $name, string|string[] $columns ) | ||
| $table | string |
The table to add the unique constraint to. |
| $name | string |
The name of the unique constraint. |
| $columns | string|string[] |
The name of the column to add the constraint on. If there are many columns, separate them with commas. |
| return | string |
The SQL statement for adding a unique constraint to an existing table. Note: The method will quote the |
|---|---|---|
public function addUnique(string $table, string $name, array|string $columns): string;
Builds an SQL statement for changing the definition of a column.
| public abstract string alterColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type ) | ||
| $table | string |
The table whose column is to change. |
| $column | string |
The name of the column to change. |
| $type | Yiisoft\Db\Schema\Column\ColumnInterface|string |
The column type which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions
into SQL representation. For example, it will convert The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}. |
| return | string |
The SQL statement for changing the definition of a column. Note: The method will quote the |
|---|---|---|
public function alterColumn(string $table, string $column, ColumnInterface|string $type): string;
Builds an SQL statement for enabling or disabling integrity check.
| public abstract string checkIntegrity ( string $schema = '', string $table = '', boolean $check = true ) | ||
| $schema | string |
The schema of the tables. Defaults to empty string, meaning the current or default schema. |
| $table | string |
The table name. Defaults to empty string, meaning that no table will be changed. |
| $check | boolean |
Whether to turn on or off the integrity check. |
| return | string |
The SQL statement for checking integrity. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string;
Builds an SQL statement for creating a new index.
| public abstract string createIndex ( string $table, string $name, array|string $columns, string|null $indexType = null, string|null $indexMethod = null ) | ||
| $table | string |
The table to create the new index for. |
| $name | string |
The name of the index. |
| $columns | array|string |
The column(s) to include in the index. If there are many columns, separate them with commas or use an array to represent them. |
| $indexType | string|null |
The index type, |
| $indexMethod | string|null |
The index organization method, if supported by DBMS.
See driver specific |
| return | string |
The SQL statement for creating a new index. |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | InvalidArgumentException | |
public function createIndex(
string $table,
string $name,
array|string $columns,
?string $indexType = null,
?string $indexMethod = null,
): string;
Builds an SQL statement for creating a new DB table.
The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name is the name of the column which will be properly quoted by the method, and definition is the type of the column which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.
The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions
into SQL representation. For example, it will convert string not null to varchar(255) not null
and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).
The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.
$this->createTable(
'example_table',
[
'id' => ColumnBuilder::primaryKey(),
'name' => ColumnBuilder::string(64)->notNull(),
'type' => ColumnBuilder::integer()->notNull()->defaultValue(10),
'description' => ColumnBuilder::text(),
'rule_name' => ColumnBuilder::string(64),
'data' => ColumnBuilder::text(),
'created_at' => ColumnBuilder::datetime()->notNull(),
'updated_at' => ColumnBuilder::datetime(),
],
);
If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly put into the generated SQL.
| public abstract string createTable ( string $table, (Yiisoft\Db\Schema\Column\ColumnInterface|Yiisoft\Db\Expression\ExpressionInterface|string)[] $columns, string|null $options = null ) | ||
| $table | string |
The name of the table to create. |
| $columns | (Yiisoft\Db\Schema\Column\ColumnInterface|Yiisoft\Db\Expression\ExpressionInterface|string)[] |
The columns (name => definition) in the new table.
The definition can be |
| $options | string|null |
More SQL fragments to append to the generated SQL. |
| return | string |
The SQL statement for creating a new DB table. Note: The method will quote the |
|---|---|---|
public function createTable(string $table, array $columns, ?string $options = null): string;
Creates an SQL View.
| public abstract string createView ( string $viewName, Yiisoft\Db\Query\QueryInterface|string $subQuery ) | ||
| $viewName | string |
The name of the view to create. |
| $subQuery | Yiisoft\Db\Query\QueryInterface|string |
The select statement which defines the view. This can be either a string or a {@see \Yiisoft\Db\QueryBuilder\Query} object. |
| return | string |
The |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
| throws | Yiisoft\Db\Exception\Exception | |
public function createView(string $viewName, QueryInterface|string $subQuery): string;
Creates an SQL command for dropping a check constraint.
| public abstract string dropCheck ( string $table, string $name ) | ||
| $table | string |
The table whose check constraint is to drop. |
| $name | string |
The name of the check constraint to drop. |
| return | string |
The SQL statement for dropping a check constraint. Note: The method will quote the |
|---|---|---|
public function dropCheck(string $table, string $name): string;
Builds an SQL statement for dropping a DB column.
| public abstract string dropColumn ( string $table, string $column ) | ||
| $table | string |
The table whose column is to drop. |
| $column | string |
The name of the column to drop. |
| return | string |
The SQL statement for dropping a DB column. Note: The method will quote the |
|---|---|---|
public function dropColumn(string $table, string $column): string;
Builds an SQL command for dropping comment to column.
| public abstract string dropCommentFromColumn ( string $table, string $column ) | ||
| $table | string |
The table whose column is to comment. |
| $column | string |
The name of the column to comment. |
| return | string |
The SQL statement for dropping comment on column. Note: The method will quote the |
|---|---|---|
public function dropCommentFromColumn(string $table, string $column): string;
Builds an SQL command for dropping comment to the table.
| public abstract string dropCommentFromTable ( string $table ) | ||
| $table | string |
The table whose column is to comment. |
| return | string |
The SQL statement for dropping comment on column. Note: The method will quote the |
|---|---|---|
public function dropCommentFromTable(string $table): string;
Creates an SQL command for dropping a default value constraint.
| public abstract string dropDefaultValue ( string $table, string $name ) | ||
| $table | string |
The table whose default value constraint is to drop. |
| $name | string |
The name of the default value constraint to drop. |
| return | string |
The SQL statement for dropping a default value constraint. Note: The method will quote the |
|---|---|---|
| throws | Yiisoft\Db\Exception\Exception | |
| throws | Yiisoft\Db\Exception\NotSupportedException |
If this isn't supported by the underlying DBMS. |
public function dropDefaultValue(string $table, string $name): string;
Builds an SQL statement for dropping a foreign key constraint.
| public abstract string dropForeignKey ( string $table, string $name ) | ||
| $table | string |
The table whose foreign is to drop. |
| $name | string |
The name of the foreign key constraint to drop. |
| return | string |
The SQL statement for dropping a foreign key constraint. Note: The method will quote the |
|---|---|---|
public function dropForeignKey(string $table, string $name): string;
Builds an SQL statement for dropping an index.
| public abstract string dropIndex ( string $table, string $name ) | ||
| $table | string |
The table whose index is to drop. |
| $name | string |
The name of the index to drop. |
| return | string |
The SQL statement for dropping an index. Note: The method will quote the |
|---|---|---|
public function dropIndex(string $table, string $name): string;
Builds an SQL statement for removing a primary key constraint to an existing table.
| public abstract string dropPrimaryKey ( string $table, string $name ) | ||
| $table | string |
The table to remove the primary key constraint from. |
| $name | string |
The name of the primary key constraint to remove. |
| return | string |
The SQL statement for removing a primary key constraint from an existing table. Note: The method will quote the |
|---|---|---|
public function dropPrimaryKey(string $table, string $name): string;
Builds an SQL statement for dropping a DB table.
| public abstract string dropTable ( string $table, boolean $ifExists = false, boolean $cascade = false ) | ||
| $table | string |
The table to drop. |
| $ifExists | boolean |
Do not throw an error if the table does not exist. |
| $cascade | boolean |
Automatically drop objects that depend on the table. |
| return | string |
The SQL statement for dropping a DB table. Note: The method will quote the |
|---|---|---|
public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): string;
Creates an SQL command for dropping a unique constraint.
| public abstract string dropUnique ( string $table, string $name ) | ||
| $table | string |
The table whose unique constraint is to drop. |
| $name | string |
The name of the unique constraint to drop. |
| return | string |
The SQL statement for dropping an unique constraint. Note: The method will quote the |
|---|---|---|
public function dropUnique(string $table, string $name): string;
Drops an SQL View.
| public abstract string dropView ( string $viewName ) | ||
| $viewName | string |
The name of the view to drop. |
| return | string |
The Note: The method will quote the |
|---|---|---|
public function dropView(string $viewName): string;
Builds an SQL statement for renaming a column.
| public abstract string renameColumn ( string $table, string $oldName, string $newName ) | ||
| $table | string |
The table whose column is to rename. |
| $oldName | string |
The old name of the column. |
| $newName | string |
The new name of the column. |
| return | string |
The SQL statement for renaming a DB column. Note: The method will quote the |
|---|---|---|
public function renameColumn(string $table, string $oldName, string $newName): string;
Builds an SQL statement for renaming a DB table.
| public abstract string renameTable ( string $oldName, string $newName ) | ||
| $oldName | string |
The table to rename. |
| $newName | string |
The new table name. |
| return | string |
The SQL statement for renaming a DB table. Note: The method will quote the |
|---|---|---|
public function renameTable(string $oldName, string $newName): string;
Builds an SQL statement for truncating a DB table.
| public abstract string truncateTable ( string $table ) | ||
| $table | string |
The table to truncate. |
| return | string |
The SQL statement for truncating a DB table. Note: The method will quote the |
|---|---|---|
public function truncateTable(string $table): string;
Signup or Login in order to comment.