Progress
Embedded SQL-92
Guide and Reference


CREATE TABLE

The CREATE TABLE statement allows you to create a new table in an existing database by defining its column names and column data types. You specify the table name for the table you are creating. Optionally, a CREATE TABLE statement can include table and column constraints.

EXAMPLE

The following code fragment illustrates a CREATE TABLE statement in an ESQL program. The cust_no column has the column constraint NOT NULL, which indicates that no row in the customer table is to have a NULL value in the cust_no column:

/* 
** CONNECT TO the DEFAULT database 
*/ 
EXEC SQL 
     CONNECT TO DEFAULT ; 
/* 
** CREATE a table with the table name customer. 
*/ 
EXEC SQL CREATE TABLE customer 
     ( 
     cust_no INTEGER NOT NULL, 
     last_name CHAR (30), 
     street CHAR (30), 
     city CHAR (20), 
     state CHAR (2) 
     ) ;  
if (sqlca.sqlcode < 0) 
{ 
     printf ("Create table statement failed (%ld : %s) \n", 
              sqlca.sqlcode, sqlca.sqlerrm); 
     EXEC SQL ROLLBACK WORK ; 
     EXEC SQL DISCONNECT DEFAULT ; 
     exit (1) ; 
} 
/* 
**  Commit the CREATE TABLE operation. 
*/ 
EXEC SQL 
     COMMIT WORK ; 
printf ("Created customer table. \n"); 
/* 
**  DISCONNECT from the DEFAULT database 
*/ 
EXEC SQL 
     DISCONNECT DEFAULT ; 

The CREATE TABLE statement also allows you to specify the DEFAULT clause along with a column definition. The DEFAULT clause identifies the default value to be used for a column, if you do not supply a value for that column in an INSERT statement.

EXAMPLE

The following CREATE TABLE statement shows how to use the DEFAULT clause. This example sets a default value of 10 for the deptno column:

EXEC SQL 
CREATE TABLE employee 
     ( 
     empno   INTEGER NOT NULL, 
     deptno  INTEGER DEFAULT 10 
     ) ; 


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095