Page 2 - DDL and DML Commands
P. 2

UNIQUE constraint
               Can be applied at table or column level.
               If applied for a column values have to be unique for the column.
               create table STUDENT
               (admNo integer NOT NULL UNIQUE,
               name varchar(50)) UNIQUE;
               Or
                       create table STUDENT
                       (admNo integer NOT NULL,
                       firstName varchar(20),
                       lastName varchar(20),
                       UNIQUE(firstName, lastName);     (unique entries for firstName + lastName, togther)


               Primary Key constraint
               Can  be applied at column or table level.
               A column specified as primary key contain unique and no null values.
                       create table STUDENT
                       (admNo integer PRIMARY KEY,
                       stream varchar(20),
                       name varchar(50));
               Or
                       create table STUDENT
                       (admNo integer,
                       stream varchar(20),
                       name varchar(50)
                       PRIMARY KEY(admNo, stream);


               Foreign Key constraint

               Can be applied at column or table level.
               Values entered in the field, must be a valid value in the primary key field of the other specified table
                       create table STUDENT
                       (admNo integer primary key,
                       name varchar(50),
                       subjectCode char(2) REFERENCES SUBJECT(subCode));
               OR
                       create table STUDENT
                       (admNo integer  primary key,
                       name varchar(50),
                       subjectCode char(2),
                       FOREIGN KEY(subjectCode) REFERENCES SUBJECT(subCode));


               Check constraint

               Can be applied at column or table level.
               Values entered in the field, must be a valid value in the primary key field of the other specified table
   1   2   3   4   5   6