next up previous
Next: Simple Inserts Up: DATA DEFINITION IN SQL Previous: DATA DEFINITION IN SQL

Schema Definition in SQL

drop table customers;
create table customers (
  cid    char(4) not null, 
  cname  varchar(13),
  city   varchar(20), 
  discnt real check(discnt >= 0.0 and discnt <= 15.0),
  primary key (cid));

drop table agents;
create table agents (
  aid     char(3) not null, 
  aname   varchar(13),
  city    varchar(20), 
  percent number(6) check(percent >= 0 and percent <= 100),
  primary key (aid));

drop table products;
create table products (
  pid       char(3) not null, 
  pname     varchar(13),
  city      varchar(20), 
  quantity  number(10) check(quantity > 0), 
  price     real check(price > 0.0),
  primary key (pid));

drop table orders;
create table orders (
  ordno   number(6) not null, 
  month   char(3),
  cid     char(4) not null, 
  aid     char(3) not null, 
  pid     char(3) not null,
  qty     number(6) not null check(qty > 0), 
  dollars float default 0.0 check(dollars >= 0.0),
  primary key (ordno),
  foreign key (cid) references customers,
  foreign key (aid) references agents,
  foreign key (pid) references products);



Raj Sunderraman
Tue Apr 1 16:15:10 PST 1997