DB2 graphic  QMF Version 8

Creating a table

To create a table, use the SQL CREATE TABLE statement:

CREATE TABLE tablename
  (columnname  datatype definition,
   columnname  datatype definition)
   IN spacename

Where:

The example in Figure 170 shows you how to create a table for an appointment calendar. The table name is CALENDAR. There are columns for the month, day, time, location, and reason for the event.

Figure 170. This table contains data for an appointment calendar.
MONTH  DAY    TIME  LOCATION          REASON
-----  ---  ------  ---------------  -------------------------------
    5     24   15.30  BIG CONF. RM.    ANNE'S BIRTHDAY PARTY
    5     25   10.45  BRIEFING CTR.    SALES CAMPAIGN KICK-OFF
 

Specifying NOT NULL prevents you from entering an appointment without a MONTH, DAY, TIME, and LOCATION. Specify a data type (character, numeric, or date/time) for each column. You must specify spacename when you create a query.

There are often several ways to specify columns and data types for a table. In this example, you can combine the MONTH and DAY columns into one column and use the DATE data type. Or, you can use the TIME data type for the time column.

If you use DATE and TIME data types, your CREATE TABLE statement looks like the one that is shown here:

CREATE TABLE CALENDAR
  (CALDATE   DATE   NOT NULL,
   TIME      TIME   NOT NULL,
   LOCATION  VARCHAR(15)  NOT NULL,
   REASON    VARCHAR(36))
IN space-name

For more information on data types, see the SQL reference manual for your database management system.


Go to the previous page Go to the next page

Downloads | Library | Support | Support Policy | Terms of use | Feedback
Copyright IBM Corporation 1982,2004 Copyright IBM Corporation 1982, 2004
timestamp Last updated: March, 2004