Using DDL

DDL is an acronym for Data Definition Language. You use DDL statements to create or modify the structure of the database. Creating or dropping tables, or changing the number of columns in a table are all done by means of the DDL.

The create.sqb program contains two examples of DDL statements: DROP TABLE and CREATE TABLE. The DROP TABLE statement causes the program to delete the specified table from the database. Conversely, the CREATE TABLE statement causes the program to create a table with the specified name in the database.

Syntax

DROP TABLE tablename
CREATE TABLE tablename (column1 [, column 2, ... ])

These statements are intended to demonstrate basic, generic syntax. However, syntax for creating tables is database dependent. When creating tables, refer to the documentation that accompanied your database.

Examples

The following statements appear in the create.sqb program.

EXEC SQL
     DROP TABLE customer
END-EXEC.
EXEC SQL
    CREATE TABLE customer 
        C_NUMBER           INTERGER NOT NULL, 
        C_FIRST_NAME       CHAR(20).
        .
        .
        .
        PRIMARY KEY        (C_NUMBER)
END-EXEC.

With these statements, the program deletes from the database any tables called customer that are owned by the user issuing the command. (The user's area of the database is called a schema). A new table by the same name is then created and defined. This precludes overwriting the original customer table.

Note: It is possible to delete tables from other areas of the database by using a qualified name. See any of the commercially available SQL texts for more information.