- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
database.createTable()
        Oxford Harrison edited this page Nov 15, 2024 
        ·
        7 revisions
      
    DOCS • API • Database API
Programmatically perform a CREATE TABLE operation.
See related ➞ CREATE TABLE
database.createTable(
    createSpec: string | TableSchemaJson,
    options?: CreateOptions
): Promise<CreateTableResult>;| Param | Interfaces | Description | 
|---|---|---|
| createSpec | TableSchemaJson | A table name, or an object specifying the intended table structure to create. | 
| options? | CreateOptions | Optional extra parameters for the query. | 
type CreateOptions = {
    ifNotExists?: boolean;
} & QueryOptions;| Param | Interfaces | Description | 
|---|---|---|
| ifNotExists? | - | An optional flag that adds an EXISTScheck to the operation. Defaults to false. | 
| Interface | Description | 
|---|---|
| QueryOptions | Inherited options. | 
type CreateTableResult = Table | TableSchema | Savepoint | null;| Type | Interfaces | Description | 
|---|---|---|
| Table | Table | For a CREATEoperation without aRETURNINGclause—an instance ofTableon the just created object. | 
| TableSchema | TableSchema | For an operation with a RETURNINGclause set toSCHEMA-the resulting database schema instance. | 
| Savepoint | null | Savepoint | For an operation with a RETURNINGclause set toSAVEPOINT-theSavepointinstance associated with the DDL operation;nullwhen savepoint creation has been disabled at the server level. | 
See examples ➞ CREATE TABLE
Specify table by name:
const table = await database.createTable(
    'table_1',
    { desc: 'Create description' }
);or by a schema object, optionally specifying a list of tables to create along with the table. (With each listed table corresponding to TableSchemaJson (in schema.json).):
const table = await database.createTable(
    {
        name: 'table_1'
        columns: [
            { name: 'column_1', type: 'int' }, 
            { name: 'column_2', type: 'time' }
        ]
    },
    { desc: 'Create description' }
);