- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:dictionary:createtablesql

# createTableSql

##### See Also

Column Attributes Reference

executeSqlArray()

##### Syntax

    array createTableSql (
        string $tableName,
        string $fields,
        optional array $tableOptions
        )

## Description

The method `createTableSql()` creates the SQL statement necessary to create a table in the database and populates it with columns defined in `$fields` option. In order to create the table, the output of the command must be executed with the executeSqlArray() method.

## Parameters

### $tableName

The table name must not yet exist in the database. Names must conform to any database specific requirements such as length limitations and name casing.

$fields is a string, not an array

### $fields

A string holding information regarding the columns to create in the new table. For a detailed description of the format of this string, see addColumnSql().

### $tableOptions

An optional array of information that adds information regarding the table creation. This array may also contain field specific information, for example information pertaining to auto-increment fields.

## Usage

    /*
    * create a data dictionary object, using the database connection
    */
    $dict = NewDataDictionary($db);

    $tabname = "UCTABLE";

    $flds = "
       COL1 C(32) NOTNULL DEFAULT 'abc',
       COL2 I  DEFAULT 0,
       COL3 N(12.2)
      ";

    /*
    * create the SQL statement necessary to create the table and its columns
    */
    $sqlarray = $dict->createTableSQL($tabname, $flds);

    /*
     * This returns (for DB2)
    Array
    (
        [0] => CREATE TABLE UCTABLE (
               COL1         VARCHAR(32) DEFAULT 'abc' NOT NULL,
               COL2         INTEGER DEFAULT 0,
               COL3         DECIMAL(12,2)
               )
    )
    */

    /*
    * This statement actually creates the table
    */
    $dict->executeSqlArray($sqlarray);

v5/dictionary/createtablesql.txt · Last modified: 2016/01/12 17:06 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top