Page 3 - DDL and DML Commands
P. 3

create table STUDENT
                       (admNo integer primary key,
                       name varchar(50),
                       age smallint CHECK(age>=14 and age<=18));
               OR
                       create table STUDENT
                       (admNo integer primary key,
                       name varchar(50),
                       age smallint CHECK(age BETWEEN 14 AND 18));
               OR
                       create table STUDENT
                       (admNo integer primary key,
                       name varchar(50),
                       age smallint,
                       stream varchar(20),
                       check(age>=14 and age<=18));

               Can be applied at table level by taking two columns:
                       create table ITEMS
                       (      icode char(3) primary key,
                              descp char(20) not null check (descp in ('NUT', 'BOLT', 'SCREW', 'WRENCH', NAIL')),
                              price float check (price>100 and price<500),
                              qoh tinyint,   # quantity on hand
                              rol tinyint,   # reorder level
                              unique(icode, descp),
                              check(ROL<QOH)
                       );


               DEFAULT value
               Specifies default value for a field
                       create table STUDENT
                       (      admNo integer primary key,
                              name varchar(50),
                              age smallint DEFAULT 15,
                              subjectcode char(2) DEFAULT '01'
                       );


               Creating Table
               create table SUBJECT
               (       subcode char(2) primary key,
                       subname varchar(50)
               );

               create table STREAM
               (       strCode smallint primary key,
                       strName varchar(15)
               );
   1   2   3   4   5   6