Vous êtes sur la page 1sur 4

C:\Temp\ABAP - Tables Script.

txt domingo, 11 de setembro de 2011 18:07


* DOMAINS
CREATE DOMAIN price AS DECIMAL (5,2) CONSTRAINT price_not_negative CHECK (VALUE) = 0) NOT
DEFERRABLE
CREATE DOMAIN revenue AS DECIMAL (9,2 ) CONSTRAINT revenue_not_negative CHECK (VALUE >=0) NOT
DEFERRABLE
CREATE DOMAIN name AS CHARACTER VARYING (50) COLLATE american_english
* TABLES
CREATE TABLE movie_titles (
title name CONSTRAINT movie_titles_not_null NOT NULL,
year_released DATE,
our_cost price,
regular_rental _price price,
current_rental_price price,
regular_sale_price price,
current_sale_price price,
part_of_series CHARACTER (3),
movie_type CHARACTER (10),
dvd_owned INTEGER,
bluray_owned INTEGER,
dvd_in_stock INTEGER,
bluray_in_stock INTEGER,
total_dvd_units_rented INTEGER,
total_bluray_units_rented INTEGER,
total_dvd_units_sold INTEGER,
total _bluray_units_sold INTEGER,
total _dvd_rental _revenue revenue,
total_bluray_rental_revenue revenue,
total_dvd_sales_revenue revenue,
total_bluray_sales_revenue revenue,
CONSTRAINT movie_titles_primary_key PRIMARY KEY (title, year_released)
)
CREATE TABLE movies_stars (
movie_title name CONSTRAINT movies_stars_movie_title_not_null NOT NULL, year_released DATE,
actor_last_name name CONSTRAINT movies_stars_actor_last_name_not_null NOT NULL,
actor_first_name name,
CONSTRAINT movies_stars_unique UNIQUE (movie_title, actor_last_name,actor_first_name) NOT
DEFERRABLE,
CONSTRAINT movies_stars_fk_movie_titles FOREIGN KEY (movie_title, year_released)
REFERENCES movie_titles (movies, year_released) ON DELETE CASCADE ON UPDATE CASCADE
)
-1-
C:\Temp\ABAP - Tables Script.txt domingo, 11 de setembro de 2011 18:07
CREATE TABLE music titles (
title name CONSTRAINT music_titles_not_null NOT NULL,
artist name CONSTRAINT artist_not_null NOT NULL,
artist_more name,
di stri butor name,
record_l abe 1 name,
type CHARACTER (10),
greatest_hits_collection CHARACTER (5),
category CHARACTER (10),
date_re 1 eased DATE,
our cost price,
list_price price,
current_price price,
still available CHARACTER (1),
cd_in_stock INTEGER,
cassette_in_stock INTEGER,
eight_track_in_stock INTEGER,
lp_in_stock INTEGER total cd sold INTEGER,
total _cassette_sold INTEGER,
total_B_track_sold INTEGER,
total _lp_sold INTEGER,
total cd returned INTEGER,
total _cassette_returned INTEGER,
total _B_track_returned INTEGER,
total_lp_returned INTEGER.
CONSTRAINT music_titles_unique UNIQUE (music_titles. artist. artist_more)
)
CREATE TABLE song_titles (
song name CONSTRAINT song_titles_song_not_null NOT NULL,
music title name,
artist name CONSTRAINT song_titles_artist_not_null NOT NULL,
artist_more name,
single CHARACTER (1),
CONSTRAINT song_titles_unique UNIQUE (song. artist. artist_more) NOT DEFERRABLE,
$TMP$TMP$TMPCONSTRAINT song_titles_fk_music_title FOREIGN KEY (music_title. artist.
artist_more)
REFERENCES music_titles (title. artist. artist_more) ON DELETE CASCADE ON UPDATE CASCADE)
)
-2-
C:\Temp\ABAP - Tables Script.txt domingo, 11 de setembro de 2011 18:07
CREATE TABLE customers (
cust_last_name name CONSTRAINT customers_cust_last_name_not_null NOT NULL.
cust_first_name name CONSTRAINT customers_cust_first_name_not_null NOT NULL,
cust_address CHARACTER VARYING (30),
cust_city CHARACTER VARYING (15),
cust_state CHARACTER (2),
cust_zip CHARACTER VARYING (9),
cust_phone CHARACTER (B),
cust_credit card CHARACTER VARYING (20)
CONSTRAINT customers_cust_credit_card_not_null NOT NULL,
cust_current_charges DECIMAL (9.2),
cust_total _charges DECIMAL (10.2),
number_of_problems SMALLINT,
last_access TIMESTAMP
)
CREATE TABLE employees (
emp_id integer CONSTRAINT employees_emp_id_pk PRIMARY KEY.
emp_last_name name CONSTRAINT employees_emp_last_name_not_null NOT NULL.
emp_first_name name CONSTRAINT employees_emp_first_name_not_nul1 NOT NULL.
emp_address CHARACTER VARYING (30).
emp_ci ty CHARACTER VARYING (15).
emp_state CHARACTER (2).
emp_zi p CHARACTER VARYI NG (9),
emp_phone CHARACTER (8),
emp_start_date DATE,
emp_hourly_rate DECIMAL (7,2)
)
-3-
C:\Temp\ABAP - Tables Script.txt domingo, 11 de setembro de 2011 18:07
* VIEWS
CREATE VIEW problem_customers (last. first. addr. city. state) AS
SELECT cust_last_name, cust_first_name, cust_address, cust_city, cust_sta1
FROM customers
WHERE number_of_problems > O.8 * (SELECT MAX (number_of_problems)
FROM customers)
GROUP BY cust_zip
CREATE VIEW employee_customers AS
SELECT emp_id. cust_current_charges
FROM customers INNER JOIN employees ON
cust_last_name = emp_last_name AND
cust_first_name = emp_first_name AND
cust_address = emp_address AND
cust_city = emp_city AND
cust_state = emp_state AND
cust_zip = emp_zip AND
cust_phone = emp_phone
WHERE cust_total_charges > 1000.00 AND
emp_hourly_rate < 5.00
CREATE VIEW emp_view AS
SELECT emp_id, emp_last_name, emp_first_name, emp_address, emp_city,
emp_state, emp_zip, emp_phone, emp_start_date, emp_hourly_rate
FROM employees
WHERE emp_id = SESSION_USER
-4-

Vous aimerez peut-être aussi