The CREATE TABLE statement defines a table. You provide the name of the table and the names and attributes of its columns. You can grant or revoke authorization for other people to use a table you created. See GRANT and REVOKE.
The syntax of the CREATE TABLE statement is:
CREATE TABLE tablename (column1 type1 NOT NULL, column2 type2 . . .) IN space-name
If your installation uses DBCS data, names of tables cannot contain double-byte characters that are internally represented as double quotation marks unless your database specifically supports double-byte characters in table names. (See Names with double-byte characters.)
If the data type is CHAR, VARCHAR, GRAPHIC, VARGRAPHIC, or DECIMAL, you must specify the maximum length of a data element, in parentheses. For DECIMAL, you must also specify the number of places after the assumed decimal point.
You can find the space-name used when QMF creates tables for SAVE DATA or IMPORT TABLE by issuing the QMF command DISPLAY PROFILE. See the appropriate Installing and Managing QMF manual for instructions on how to find and provide these names to users.
The following CREATE statement defines a table called PERS. The columns in PERS have the same characteristics as Q.STAFF, but contain no data.
CREATE TABLE PERS (ID SMALLINT NOT NULL, NAME VARCHAR(9), DEPT SMALLINT, JOB CHAR(5), YEARS SMALLINT, SALARY DECIMAL(7,2), COMM DECIMAL(7,2)) IN space-name
You can use NOT NULL with any set of columns in the CREATE TABLE statement; in the example, it appears with column ID. It means that any row entered into PERS must have, at the very least, an employee number.
This statement defines the Q.APPLICANT table:
CREATE TABLE APPLICANT (TEMPID SMALLINT NOT NULL, NAME VARCHAR(9), ADDRESS VARCHAR(17), EDLEVEL SMALLINT, COMMENTS VARCHAR(29)) IN space-name
This statement defines the Q.INTERVIEW table:
CREATE TABLE INTERVIEW (TEMPID SMALLINT, INTDATE DATE, STARTTIME TIME, ENDTIME TIME, MANAGER SMALLINT, DISP VARCHAR(6), LASTNAME VARCHAR(9), FIRSTNAME VARCHAR(9)) IN space-name
Defining the table does not put data into it. For ways of entering data into it, see INSERT INTO.
[ Previous Page | Next Page | Contents | Index ]