Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Chapter 5.

Creating databases and tables

Creating a simple database:


The database should be created only on the node or database
partition that issues the CREATE DATABASE command or across all the
partitions in the system.
Syntax is-
CREATE DATABASE <Database Name>

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 > , …)

Adding data to tables:


It is used to add new rows to a table or view. Inserting a row
into a view also insert the row into the table on which the view is based.
Syntax is-
INSERT INTO<Table Name> (id, name, dept) VALUES (007,’blue’, 66)

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.

Data in tables can be related to data in one or more tables with


referential integrity. Constraints can also be imposed on data values so that
they conform to a certain property or business rule. For example, if a table
column stores the sex of a person, the constraint can enforce that the only
values allowed are “M” for male, and “F” for female.

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>

You might also like