Skip to content

Create Table

The CREATE command is used to create any table:

    CREATE TABLE <name> (
        A1  D1,
        A2  D2,
        A3  D3,
        <integrity constraint 1>,
        <integrity constraint 2>
    );
  • A\(\,_i\) is an attribute of the table. D\(\,_i\) is the domain / datatype of said attribute

Integrity Constraints

  • Integrity constraints tells us some information about the attribute that decides its integrity. They include:
    • primary key (\(A_1, A_2, ... A_n\))
    • foreign key (\(A_m, .... A_n\))
    • not null
    CREATE TABLE instructor (
        ID          char(5),
        name        varchar(20) NOT NULL,
        dept_name   varchar(20),
        salary      numeric(8, 2),

        primary key (ID),
        foreign key (dept_name) references department
    );