Table
Table
Provides SQL table management helpers for DBI drivers.
trait TableIncludes table discovery, creation, alteration, deletion, and metadata inspection utilities, along with support for related schema features.
Methods
listTables
Lists base tables in the active schema.
public listTables(): arrayReturns: array
tableExists
Checks whether a table exists in the current schema.
public tableExists(string $tableName): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the table name to check |
createTable
Creates a new table using the provided column definition map.
public createTable(string $tableName, array $columns): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the table name to create |
$columns | array | column specifications keyed by column name or provided as numeric entries with a name field |
describeTable
Describes columns for a table in the current schema.
public describeTable(string $tableName, ?string $sort): array|falseReturns: array|false
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the table name to inspect |
$sort | string | optional column name used to sort metadata rows |
renameTable
Renames an existing table.
public renameTable(string $fromName, string $toName): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$fromName | string | current table name |
$toName | string | new table name |
dropTable
Drops a table from the database.
public dropTable(string $name, bool $ifExists, bool $cascade): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | table name to drop |
$ifExists | bool | when true, includes IF EXISTS |
$cascade | bool | when true, cascades to dependent objects |
addColumn
Adds a column to an existing table.
public addColumn(string $tableName, array $columnSpec): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | target table name |
$columnSpec | array | column specification including at least name and type |
alterColumn
Alters an existing column definition.
public alterColumn(string $tableName, string $column, array $columnSpec): boolReturns: bool
Supported operations include rename, type changes, nullability, and default updates.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | target table name |
$column | string | existing column name |
$columnSpec | array | alteration specification |
dropColumn
Drops a column from a table.
public dropColumn(string $tableName, string $column, bool $ifExists): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | target table name |
$column | string | column name to drop |
$ifExists | bool | when true, includes IF EXISTS clauses |
truncate
TRUNCATE empty a table or set of tables.
public truncate(string $tableName, bool $only, bool $restartIdentity, bool $cascade): boolReturns: bool
TRUNCATE quickly removes all rows from a set of tables. It has the same effect as an unqualified DELETE on each table, but since it does not actually scan the tables it is faster. Furthermore, it reclaims disk space immediately, rather than requiring a subsequent VACUUM operation. This is most useful on large tables.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table(s) to truncate. Multiple tables are supported. |
$only | bool | Only the named table is truncated. If FALSE, the table and all its descendant tables (if any) are truncated. |
$restartIdentity | bool | Automatically restart sequences owned by columns of the truncated table(s). The default is to no restart. |
$cascade | bool | If TRUE, automatically truncate all tables that have foreign-key references to any of the named tables, or to any tables added to the group due to CASCADE. If FALSE, Refuse to truncate if any of the tables have foreign-key references from tables that are not listed in the command. FALSE is the default. |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000