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(): voidtableExists
Checks whether a table exists in the current schema.
public tableExists(string $tableName): boolParameters
| 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, mixed $columns): boolParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the table name to create |
$columns | mixed | 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, false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | the table name to inspect |
$sort | string | optional column name used to sort metadata rows |
$ | false |
renameTable
Renames an existing table.
public renameTable(string $fromName, string $toName): boolParameters
| 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): boolParameters
| 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, mixed $columnSpec): boolParameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | target table name |
$columnSpec | mixed | column specification including at least name and type |
alterColumn
Alters an existing column definition.
public alterColumn(string $tableName, string $column, mixed $columnSpec): boolSupported operations include rename, type changes, nullability, and default updates.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | target table name |
$column | string | existing column name |
$columnSpec | mixed | alteration specification |
dropColumn
Drops a column from a table.
public dropColumn(string $tableName, string $column, bool $ifExists): boolParameters
| 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): boolTRUNCATE 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 Tue, 21 Apr 2026 04:00:24 +0000