You are on page 1of 10

DROP

DROP
DROP
DROP
DROP
DROP
DROP
DROP
DROP
DROP

TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE

preferences PURGE;
consignment PURGE;
sale_agreement PURGE;
service_agreement PURGE;
purchase_agreement PURGE;
customer PURGE;
employee PURGE;
supplier PURGE;
artwork PURGE;
service PURGE;

CREATE TABLE customer


(customer_id NUMBER(6)
CONSTRAINT cust_id_pk PRIMARY KEY,
first_name VARCHAR2(30)
CONSTRAINT cust_fn_nn NOT NULL,
last_name VARCHAR2(30)
CONSTRAINT cust_ln_nn NOT NULL,
street_address VARCHAR2(30),
city VARCHAR2(30),
state VARCHAR2(2),
zip_code VARCHAR2(5));
CREATE TABLE preferences
(preference_id NUMBER(6)
CONSTRAINT pref_id_pk PRIMARY KEY,
willing_to_pay NUMBER(10,2),
artist_name VARCHAR2(30),
type_of_art VARCHAR2 (30),
notes VARCHAR2(180),
customer_id NUMBER(6)
CONSTRAINT pref_cid_fk REFERENCES customer(customer_id)
CONSTRAINT pref_cid_nn NOT NULL);
CREATE TABLE employee
(employee_id NUMBER(6)
CONSTRAINT emp_id_pk PRIMARY KEY,
first_name VARCHAR2(30)
CONSTRAINT emp_fn_nn NOT NULL,
last_name VARCHAR2(30)
CONSTRAINT emp_ln_nn NOT NULL,
street_address VARCHAR2(30),
city VARCHAR2(30),
state VARCHAR2(2),
zip_code VARCHAR2(5),
type VARCHAR2(2)
CONSTRAINT emp_type_ck CHECK(type IN('SA','SE','MA'))
CONSTRAINT emp_type_nn NOT NULL,
hourly_salary NUMBER(5,2),
annual_salary NUMBER(8,2),
CONSTRAINT emp_sal_ck CHECK(
((type = 'SA' or type = 'MA') AND hourly_salary IS NULL AND annual_salary IS NO
T NULL)
OR
(type = 'SE' AND hourly_salary IS NOT NULL AND annual_salary IS NULL)));
CREATE OR REPLACE VIEW sales_employee
AS
SELECT employee_id, first_name, last_name, street_address, city, state, zip_code
, type, annual_salary

FROM employee
WHERE type = 'SA';
CREATE OR REPLACE VIEW manager
AS
SELECT employee_id, first_name, last_name, street_address, city, state, zip_code
, type, annual_salary
FROM employee
WHERE type = 'MA';
CREATE OR REPLACE VIEW service_employee
AS
SELECT employee_id, first_name, last_name, street_address, city, state, zip_code
, type, hourly_salary
FROM employee
WHERE type = 'SE';
CREATE TABLE service
(service_id NUMBER(6)
CONSTRAINT serv_servid_pk PRIMARY KEY,
cost NUMBER(4)
CONSTRAINT serv_cost_nn NOT NULL,
type VARCHAR2(20)
CONSTRAINT serv_type_nn NOT NULL,
description VARCHAR2(40));
CREATE TABLE artwork
(art_id NUMBER(6)
CONSTRAINT art_aid_pk PRIMARY KEY,
artist VARCHAR2(30)
CONSTRAINT art_artist_nn NOT NULL,
short_desc VARCHAR2(20),
base_price NUMBER(10,2)
CONSTRAINT art_bp_ck CHECK(base_price > 0),
min_price NUMBER(10,2),
date_created DATE,
height NUMBER(4,2),
width NUMBER(4,2),
length NUMBER(4,2),
city_origin VARCHAR2(30),
country_origin VARCHAR2(30),
description VARCHAR2(100),
title VARCHAR2(35),
art_type VARCHAR2(20),
weight NUMBER(6,2),
material VARCHAR2(20),
media VARCHAR2(20),
style VARCHAR2(20),
numbered NUMBER(6),
signed VARCHAR2(1)
CONSTRAINT art_sign_ck CHECK(signed IN ('Y','N')),
one_of_a_kind VARCHAR2(1)
CONSTRAINT art_ooak_ck CHECK(one_of_a_kind IN ('Y','N')),
category VARCHAR2(9)
CONSTRAINT art_cat_ck CHECK(category IN ('SCULPTURE','PAINTING','PHOTO')
),
CONSTRAINT art_mp_ck CHECK(base_price > 0 AND min_price < base_price));
CREATE OR REPLACE VIEW sculpture
AS

SELECT art_id, artist, title, short_desc, base_price, date_created, height, widt


h, length, weight,
material, city_origin, country_origin, description, art_type, category
FROM artwork
WHERE category = 'SCULPTURE';
CREATE OR REPLACE VIEW painting
AS
SELECT art_id, artist, title, short_desc, base_price, date_created, media, style
, height, width,
length, city_origin, country_origin, description, category
FROM artwork
WHERE category = 'PAINTING';
CREATE OR REPLACE VIEW photograph
AS
SELECT art_id, artist, title, art_type, short_desc, base_price, date_created, he
ight, width, length,
city_origin, country_origin, description, signed, one_of_a_kind, numbered, ca
tegory
FROM artwork
WHERE category = 'PHOTO';
CREATE TABLE supplier
(supplier_id NUMBER(6)
CONSTRAINT sup_supid_pk PRIMARY KEY,
first_name VARCHAR2(30)
CONSTRAINT sup_fn_nn NOT NULL,
last_name VARCHAR2(30)
CONSTRAINT sup_ln_nn NOT NULL,
street_address VARCHAR2(30),
city VARCHAR2(30),
state VARCHAR2(2),
zip_code VARCHAR2(5),
supplier_type VARCHAR(8)
CONSTRAINT sup_type_ck CHECK (supplier_type IN('GALLERY','ARTHOUSE','ART
IST')));
CREATE TABLE service_agreement
(service_agreement_id NUMBER(6)
CONSTRAINT sera_seragid_pk PRIMARY KEY,
service_id NUMBER (6)
CONSTRAINT sera_serid_fk REFERENCES service(service_id),
customer_id NUMBER(6)
CONSTRAINT sera_cid_fk REFERENCES customer (customer_id),
art_id NUMBER(6)
CONSTRAINT sera_aid_fk REFERENCES artwork (art_id),
description VARCHAR(50));
CREATE TABLE purchase_agreement
(purchase_id NUMBER(6)
CONSTRAINT pur_pid_pk PRIMARY KEY,
supplier_id NUMBER(6)
CONSTRAINT pur_supid_fk REFERENCES supplier(supplier_id),
art_id NUMBER(6)
CONSTRAINT pur_aid_fk REFERENCES artwork (art_id)
CONSTRAINT pur_aid_uk UNIQUE
CONSTRAINT pur_aid_nn NOT NULL,
purchase_cost NUMBER(11,2)
CONSTRAINT pur_pc_nn NOT NULL,

date_of_purchase DATE
CONSTRAINT pur_dop_nn NOT NULL);
CREATE TABLE sale_agreement
(sale_id NUMBER(6)
CONSTRAINT sa_saleid_pk PRIMARY KEY,
customer_id NUMBER(6)
CONSTRAINT sa_cid_fk REFERENCES customer (customer_id),
art_id NUMBER(6)
CONSTRAINT sa_aid_fk REFERENCES artwork (art_id)
CONSTRAINT sa_aid_uk UNIQUE
CONSTRAINT sa_aid_nn NOT NULL,
date_of_sale DATE
CONSTRAINT sa_dos_nn NOT NULL);
CREATE TABLE consignment
(consign_id NUMBER(6)
CONSTRAINT cons_cid_pk PRIMARY KEY,
supplier_id NUMBER(6)
CONSTRAINT cons_conid_fk REFERENCES supplier(supplier_id)
CONSTRAINT cons_conid_nn NOT NULL,
art_id NUMBER (6)
CONSTRAINT cons_aid_fk REFERENCES artwork(art_id)
CONSTRAINT cons_aid_uk UNIQUE
CONSTRAINT cons_aid_nn NOT NULL,
sell_price NUMBER(10,2)
CONSTRAINT cons_sp_ck CHECK (sell_price > 0),
min_price NUMBER(10,2)
CONSTRAINT cons_mp_ck CHECK (min_price > 0),
start_date DATE,
end_date DATE,
CONSTRAINT cons_datech_ck CHECK(end_date >= start_date),
CONSTRAINT cons_subtype_ck CHECK(min_price<sell_price));
CREATE OR REPLACE VIEW sculpture_sale
AS
SELECT
sa.sale_id,
c.customer_id,
c.first_name,
c.last_name,
c.street_address,
c.city,
c.state,
c.zip_code,
s.art_id,
s.artist,
s.title,
s.short_desc,
s.base_price,
s.base_price * .0725 AS "Tax",
s.base_price + s.base_price * .0725 AS total,
s.date_created,
s.height,
s.width,
s.length,
s.weight,
s.material,
s.city_origin,
s.country_origin,

s.description,
s.art_type,
s.category
FROM customer c
JOIN sale_agreement sa
ON (c.customer_id = sa.customer_id)
JOIN sculpture s
ON (sa.art_id = s.art_id);
CREATE OR REPLACE VIEW painting_sale
AS
SELECT
sa.sale_id,
c.customer_id,
c.first_name,
c.last_name,
c.street_address,
c.city,
c.state,
c.zip_code,
p.art_id,
p.artist,
p.title,
p.short_desc,
p.base_price,
p.base_price * .0725 AS "Tax",
p.base_price + p.base_price * .0725 AS total,
p.date_created,
p.media,
p.style,
p.height,
p.width,
p.length,
p.city_origin,
p.country_origin,
p.description,
p.category
FROM customer c
JOIN sale_agreement sa
ON (c.customer_id = sa.customer_id)
JOIN painting p
ON (sa.art_id = p.art_id);
CREATE OR REPLACE VIEW photograph_sale
AS
SELECT
sa.sale_id,
c.customer_id,
c.first_name,
c.last_name,
c.street_address,
c.city,
c.state,
c.zip_code,
p.art_id,
p.artist,
p.title,
p.art_type,
p.short_desc,
p.base_price,

p.base_price * .0725 AS "Tax",


p.base_price + p.base_price * .0725 AS "Total Price",
p.date_created,
p.height,
p.width,
p.length,
p.city_origin,
p.country_origin,
p.description,
p.signed,
p.one_of_a_kind,
p.numbered,
p.category
FROM customer c
JOIN sale_agreement sa
ON (c.customer_id = sa.customer_id)
JOIN photograph p
ON (sa.art_id = p.art_id);
CREATE OR REPLACE VIEW service_sale
AS
SELECT
sa.service_agreement_id,
c.customer_id,
c.first_name,
c.last_name,
c.street_address,
c.city,
c.state,
c.zip_code,
s.service_id,
s.cost,
s.type,
s.description
FROM customer c
JOIN service_agreement sa
ON (c.customer_id = sa.customer_id)
JOIN service s
ON (sa.service_id = s.service_id);
CREATE OR REPLACE VIEW sculpture_purchase
AS
SELECT
pa.purchase_id,
pa.purchase_cost,
su.supplier_id,
su.first_name,
su.last_name,
su.street_address,
su.city,
su.state,
su.zip_code,
su.supplier_type,
s.art_id,
s.artist,
s.title,
s.short_desc,
s.base_price,
s.date_created,
s.height,

s.width,
s.length,
s.weight,
s.material,
s.city_origin,
s.country_origin,
s.description,
s.art_type,
s.category
FROM supplier su
JOIN purchase_agreement pa
ON (su.supplier_id = pa.supplier_id)
JOIN sculpture s
ON (pa.art_id = s.art_id);
CREATE OR REPLACE VIEW painting_purchase
AS
SELECT
pa.purchase_id,
pa.purchase_cost,
su.supplier_id,
su.first_name,
su.last_name,
su.street_address,
su.city,
su.state,
su.zip_code,
su.supplier_type,
p.art_id,
p.artist,
p.title,
p.short_desc,
p.base_price,
p.date_created,
p.media,
p.style,
p.height,
p.width,
p.length,
p.city_origin,
p.country_origin,
p.description,
p.category
FROM supplier su
JOIN purchase_agreement pa
ON (su.supplier_id = pa.supplier_id)
JOIN painting p
ON (pa.art_id = p.art_id);
CREATE OR REPLACE VIEW photograph_purchase
AS
SELECT
pa.purchase_id,
pa.purchase_cost,
su.supplier_id,
su.first_name,
su.last_name,
su.street_address,
su.city,
su.state,

su.zip_code,
su.supplier_type,
p.art_id,
p.artist,
p.title,
p.short_desc,
p.base_price,
p.date_created,
p.height,
p.width,
p.length,
p.city_origin,
p.country_origin,
p.description,
p.signed,
p.one_of_a_kind,
p.numbered,
p.art_type,
p.category
FROM supplier su
JOIN purchase_agreement pa
ON (su.supplier_id = pa.supplier_id)
JOIN photograph p
ON (pa.art_id = p.art_id);
CREATE OR REPLACE VIEW sculpture_consignment
AS
SELECT
con.consign_id,
su.supplier_id,
su.first_name,
su.last_name,
su.street_address,
su.city,
su.state,
su.zip_code,
con.sell_price,
con.min_price,
con.start_date,
con.end_date,
s.art_id,
s.artist,
s.title,
s.short_desc,
s.date_created,
s.height,
s.width,
s.length,
s.weight,
s.material,
s.city_origin,
s.country_origin,
s.description,
s.art_type,
s.category
FROM supplier su
JOIN consignment con
ON (su.supplier_id = su.supplier_id)
JOIN sculpture s
ON (con.art_id = s.art_id);

CREATE OR REPLACE VIEW painting_consignment


AS
SELECT
con.consign_id,
su.supplier_id,
su.first_name,
su.last_name,
su.street_address,
su.city,
su.state,
su.zip_code,
p.art_id,
p.artist,
p.title,
p.short_desc,
p.date_created,
p.media,
p.style,
p.height,
p.width,
p.length,
p.city_origin,
p.country_origin,
p.description,
p.category
FROM supplier su
JOIN consignment con
ON (su.supplier_id = su.supplier_id)
JOIN painting p
ON (con.art_id = p.art_id);
CREATE OR REPLACE VIEW photograph_consignment
AS
SELECT
con.consign_id,
su.supplier_id,
su.first_name,
su.last_name,
su.street_address,
su.city,
su.state,
su.zip_code,
p.art_id,
p.artist,
p.title,
p.art_type,
p.short_desc,
p.date_created,
p.height,
p.width,
p.length,
p.city_origin,
p.country_origin,
p.description,
p.signed,
p.one_of_a_kind,
p.numbered,
p.category
FROM supplier su

JOIN consignment con


ON (su.supplier_id = su.supplier_id)
JOIN photograph p
ON (con.art_id = p.art_id);

You might also like