CREATE TABLE
statement.CREATE TABLE
statementCREATE TABLE
statement. The following shows the simplified syntax of the CREATE TABLE
statement:NOT NULL
and CHECK
constraint.PRIMARY KEY
, FOREIGN KEY
and CHECK
constraints. Note that you’ll learn more about these constraints in the next tutorial.CREATE TABLE
exampleCREATE TABLE
statement to create a new table named stores
:stores
table:store_id
column is an integer column. The GENERATED BY DEFAULT AS IDENTITY
clause marks the store_id
column as an identity column so that when you insert a new row into the stores
table, Db2 will automatically generate a sequential integer for the store_id
column. The NOT NULL
constraint ensures that the store_id
will not accept any NULL value.store_name
is a varying character (VARCHAR
) column with a maximum length of 150. It has a NOT NULL
constraint that will enforce non-null values.address_line_1
is also a varying character column with a maximum length of 255 and does not accept NULL.address_line_2
is a varying character column with a maximum length of 100. The address_line_2
is a nullable column so it can store NULL values.city_id
and state_id
are integer columns. They accept NULL values.zip_code
column is a varying character column with a maximum length of 6. It is a nullable column.store_id
is the primary key column of the stores
table specified by the PRIMARY KEY
constraint at the end of the statement. It means that the store_id will store unique values that identify all rows of the table.CREATE TABLE
statement, you will find the stores
table appears in the database catalog. The stores
table is empty once created. You can view its content by using the following SELECT
statement:stores
table, you use the INSERT
statement.CREATE TABLE
statement to create a new table in a database.