A Sample Database


The database below, including three tables, stores, products, and sales_fact, will be used in the following slides, which show how to connect the Web to a database.


   DROP SEQUENCE store_seq;
   CREATE SEQUENCE store_seq START WITH 1 INCREMENT BY 1 CACHE 100;
   DROP TABLE stores;
   CREATE TABLE stores (
     store_key  INTEGER PRIMARY KEY,
     city       VARCHAR(32) NOT NULL,
     region     VARCHAR(16) NOT NULL );

   INSERT INTO stores VALUES( store_seq.NEXTVAL, 'New York', 'East' );
   INSERT INTO stores VALUES( store_seq.NEXTVAL, 'Chicago', 'Central' );
   INSERT INTO stores VALUES( store_seq.NEXTVAL, 'Atlanta', 'East' );
   INSERT INTO stores VALUES( store_seq.NEXTVAL, 'Los Angeles', 'West' );
   INSERT INTO stores VALUES( store_seq.NEXTVAL, 'San Francisco', 'West' );
   INSERT INTO stores VALUES( store_seq.NEXTVAL, 'Philadelphia', 'East' );

   DROP SEQUENCE product_seq;
   CREATE SEQUENCE product_seq START WITH 1 INCREMENT BY 1 CACHE 100;
   DROP TABLE products;
   CREATE TABLE products (
     product_key  INTEGER PRIMARY KEY,
     description  VARCHAR(32) NOT NULL,
     brand        VARCHAR(32) NOT NULL );

   INSERT INTO products VALUES( product_seq.NEXTVAL, 'Beautiful Girls', 'MKF Studios' );
   INSERT INTO products VALUES( product_seq.NEXTVAL, 'Toy Story', 'Wolf' );
   INSERT INTO products VALUES( product_seq.NEXTVAL, 'Sense and Sensibility', 'Parabuster Inc.' );
   INSERT INTO products VALUES( product_seq.NEXTVAL, 'Holiday of the Year', 'Wolf' );
   INSERT INTO products VALUES( product_seq.NEXTVAL, 'Pulp Fiction', 'MKF Studios' );
   INSERT INTO products VALUES( product_seq.NEXTVAL, 'The Juror', 'MKF Studios' );
   INSERT INTO products VALUES( product_seq.NEXTVAL, 'From Dusk till Dawn', 'Parabuster Inc.' );
   INSERT INTO products VALUES( product_seq.NEXTVAL, 'Hellraiser: Bloodline', 'Big Studios' );

   DROP TABLE sales_fact;
   CREATE TABLE sales_fact (
     store_key    INTEGER,
     product_key  INTEGER,
     sales        NUMBER(5,2) NOT NULL,
     cost         NUMBER(5,2) NOT NULL,
     profit       NUMBER(5,2) NOT NULL,
     PRIMARY KEY ( store_key, product_key ),
     FOREIGN KEY ( store_key ) REFERENCES stores( store_key ) ON DELETE CASCADE,
     FOREIGN KEY ( product_key ) REFERENCES products( product_key ) ON DELETE CASCADE );

   INSERT INTO sales_fact VALUES( 1, 6,  2.39, 1.15, 1.24 );
   INSERT INTO sales_fact VALUES( 1, 2, 16.70, 6.91, 9.79 );
   INSERT INTO sales_fact VALUES( 2, 7,  7.16, 2.75, 4.40 );
   INSERT INTO sales_fact VALUES( 3, 2,  4.77, 1.84, 2.93);
   INSERT INTO sales_fact VALUES( 5, 3, 11.93, 4.59, 7.34 );
   INSERT INTO sales_fact VALUES( 5, 1, 14.31, 6.51, 8.80);