Declaring and Creating a Table

From InterBase
Jump to: navigation, search

In programs that mix data definition and data manipulation, the DECLARE TABLE statement must be used to describe a structure of a table to the InterBase preprocessor, gpre, before that table can be created. During preprocessing, if gpre encounters a DECLARE TABLE statement, it stores the description of a table for later reference. When gpre encounters a CREATE TABLE statement for the previously declared table, it verifies that the column descriptions in the CREATE statement match those in the DECLARE statement. If they do not match, gpre reports the errors and cancels preprocessing so that the error can be fixed.

When used, DECLARE TABLE must come before the CREATE TABLE statement it describes. For example, the following code fragment declares a table,
EMPLOYEE_PROJ, then creates it:

EXEC SQL
DECLARE EMPLOYEE_PROJECT TABLE
(
EMP_NO SMALLINT,
PROJ_ID CHAR(5),
DUTIES Blob(240, 1)
);
EXEC SQL
CREATE TABLE EMPLOYEE_PROJECT
(
EMP_NO SMALLINT,
PROJ_ID CHAR(5),
DUTIES Blob(240, 1)
);
EXEC SQL
COMMIT;

For more information about DECLARE TABLE, see the Language Reference Guide.