Professional Documents
Culture Documents
Chapter 5. Creating Databases and Tables: Creating A Simple Database
Chapter 5. Creating Databases and Tables: Creating A Simple Database
Creating Tables:
Tables are created through data definition language (DDL)
requests to the database manager. The database manager controls changes
and access to the data stored in the tables. You request a change to the
content of the table through the database manager by using a data
manipulation language (DML) statement. Both DDL and the DML are
subset languages of structured query language (SQL).
Syntax is-
CREATE TABLE <Table Name> (<column name> <data type> <column options> ,
<column name> <data type> <column options > , …)
Referential integrity:
Referential integrity allows your database to manage
relationships between tables. You can establish parent-child type of
relationships between tables as shown in Figure. There are two tables,
DEPARTMENT and EMPLOYEE, related by the department number. The
WORKDEPT column in the EMPLOYEE table can only contain department
numbers that already exist in the DEPARTMENT table. This is because in
this example, the DEPARTMENT table is the parent table, and the
EMPLOYEE table is the child, or dependent, table. The figure also shows
the necessary CREATE TABLE statement for the EMPLOYEE table needed
to establish the relationship.
Altering Table:
The ALTER TABLE statement modifies an existing table by
adding one or more columns; adding or dropping a primary key; adding or
dropping one or more unique or referential constraints; adding or dropping
one or more check constraint definitions; altering the length of a VARCHAR
column; altering a reference type column to add a scope; altering the
generation expression of a generated column; adding or dropping a
partitioning key; changing table attributes, such as the data capture option
pctfree, lock size, or append mode; or setting the table to the not logged
initially state.
Syntax is-
ALTER TABLE <Table Name>