Professional Documents
Culture Documents
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;
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
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,
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);