Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this assignment you will perform the physical design and implementation using

ID: 3794567 • Letter: I

Question

In this assignment you will perform the physical design and implementation using SQL Data Definition Language (DDL) and proceed with populating the Mom and Pop Johnson Video Store database via Data Manipulation Language (DML) SQL commands.

For each of the steps below you may create a separate SQL script file and SPOOL file or you may want to put the SPOOL output for several steps, from the same SQL script file, in the same file. Be sure your SPOOL file(s) contains your SQL statements along with the Oracle responses and/or displayed results.

Assignment Details:

Create Oracle database tables using SQL Data Definition Language (DDL) for each table listed in the metadata of Assignment 1. You may need to use a combination of DROP TABLE, CREATE TABLE, and ALTER TABLE SQL statements. Make sure that entity and referential integrity are enforced by declaring a primary key for each table (these may be composite keys) and declaring all appropriate foreign keys. Your CREATE TABLE and ALTER TABLE statements (if desired) must show integrity constraints, as appropriate, for NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, REFERENCES, and CHECK constraints. Be sure to save your SQL script file used to create these tables with a .sql extension and your output SPOOL file with a .lst or .txt extension. You should rerun and test your SQL script file until it runs without any errors (this is why you’ll want to include DROP TABLE statements). Submit your SPOOL file showing that all SQL in your SQL script file worked properly.

Populate each of your tables with at least five valid rows of data each and show the SQL INSERT statements as you executed them. Populate other tables in your database, as necessary, to satisfy referential integrity. Save your SQL script file and SPOOL file with the correct extensions. You should test and rerun your SQL script file until it runs without any error. Submit your SPOOL file showing that all SQL in your SQL script file worked properly.

Develop an SQL script file to perform the following queries and updates. You should test your SQL script file until it runs without any errors.

Retrieve all of your customers' names, account numbers, and addresses (street and zip code only), sorted by account number.

Retrieve all of the videos rented in the last 30 days and sort in chronological rental date order.

Produce a list of your distributors and all their information sorted in order by company name.

Update a customer name to change their maiden name to a married name. You can choose which row to update. Make sure that you use the primary key column in your WHERE clause to affect only a specific row. You may want to include a ROLLBACK statement to undo your data update.

Delete a customer from the database. You can choose which row to delete. Make sure that you use the primary key column in your WHERE clause to affect only a specific row. You may want to include a ROLLBACK statement to undo your data deletion.

Ensure that you use the commands below in order to create your single SPOOL file and showing that all SQL in your SQL script files worked properly. Show the actual SQL statements executed and the results the SQL produced below the code by making sure that you have a SET ECHO STATEMENT in your SQL script file(s).

You will be submitting a number of files.

A Word/PDF document with our ERD and documentation.

Submit your SPOOL file(s) showing that all SQL in your SQL script file worked properly. Show the actual SQL statements executed and the results the SQL produced below the code.

You should also submit all of your .sql scripts.

Explanation / Answer

CREATE SEQUENCE SEQ_academy_awards_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_academy_awards_movies_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_actors_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_actors_movies_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_charges_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_charges_rentals_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_customers_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_directors_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_directors_movies_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_distributors_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_inventories_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_movies_id INCREMENT BY 1 START WITH 1; CREATE SEQUENCE SEQ_rentals_id INCREMENT BY 1 START WITH 1; /* Create Tables */ CREATE TABLE academy_awards ( id number(5,0) NOT NULL, category varchar2(25) NOT NULL, year_awarded number(5,0) NOT NULL, is_winner varchar2(1) NOT NULL, is_nominee varchar2(1) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE academy_awards_movies ( id number(10,0) NOT NULL, academy_award_id number(5,0) NOT NULL, movie_id number(5,0) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE actors ( id number(5,0) NOT NULL, first_name varchar2(15) NOT NULL, middle_name varchar2(15), last_name varchar2(15) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE actors_movies ( id number(10,0) NOT NULL, actor_id number(5,0) NOT NULL, movie_id number(5,0) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE charges ( id number(3,0) NOT NULL, -- standard_charge -- late_fee -- damaged_fee -- failure_to_rewind_fee -- other charge_type varchar2(30) NOT NULL, charge number(19,4) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE charges_rentals ( id number(10,0) NOT NULL, rental_id number(10,0) NOT NULL, charge_id number(3,0) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE customers ( id number(5,0) NOT NULL, first_name varchar2(15) NOT NULL, middle_name varchar2(15), last_name varchar2(15) NOT NULL, street_address varchar2(30) NOT NULL, city varchar2(15) NOT NULL, state varchar2(5) NOT NULL, zip_code number(10,0) NOT NULL, phone_number varchar2(20) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE directors ( id number(5,0) NOT NULL, first_name varchar2(15) NOT NULL, middle_name varchar2(15), last_name varchar2(15) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE directors_movies ( id number(10,0) NOT NULL, director_id number(5,0) NOT NULL, movie_id number(5,0) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE distributors ( id number(3,0) NOT NULL, name varchar2(40) NOT NULL, shipment_quantity number(5,0), PRIMARY KEY (id) ); CREATE TABLE inventories ( id number(10,0) NOT NULL, movie_id number(5,0) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE movies ( id number(5,0) NOT NULL, distributor_id number(3,0) NOT NULL, title varchar2(50) NOT NULL, -- suspense -- horror -- mystery -- comedy -- other movie_type varchar2(15) NOT NULL, running_length number(5,0) NOT NULL, rating number(3,0), year_released number(5,0) NOT NULL, is_video varchar2(1) NOT NULL, is_dvd varchar2(1) NOT NULL, wholesale_price number(19,4) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE rentals ( id number(10,0) NOT NULL, customer_id number(5,0) NOT NULL, inventory_id number(10,0) NOT NULL, rental_date date NOT NULL, return_due_date date NOT NULL, is_rented varchar2(1) NOT NULL, is_returned varchar2(1) NOT NULL, total_charge number(19,4) NOT NULL, tax number(19,4) NOT NULL, PRIMARY KEY (id) ); /* Create Foreign Keys */ ALTER TABLE academy_awards_movies ADD FOREIGN KEY (academy_award_id) REFERENCES academy_awards (id) ; ALTER TABLE actors_movies ADD FOREIGN KEY (actor_id) REFERENCES actors (id) ; ALTER TABLE charges_rentals ADD FOREIGN KEY (charge_id) REFERENCES charges (id) ; ALTER TABLE rentals ADD FOREIGN KEY (customer_id) REFERENCES customers (id) ; ALTER TABLE directors_movies ADD FOREIGN KEY (director_id) REFERENCES directors (id) ; ALTER TABLE movies ADD FOREIGN KEY (distributor_id) REFERENCES distributors (id) ; ALTER TABLE rentals ADD FOREIGN KEY (inventory_id) REFERENCES inventories (id) ; ALTER TABLE directors_movies ADD FOREIGN KEY (movie_id) REFERENCES movies (id) ; ALTER TABLE actors_movies ADD FOREIGN KEY (movie_id) REFERENCES movies (id) ; ALTER TABLE academy_awards_movies ADD FOREIGN KEY (movie_id) REFERENCES movies (id) ; ALTER TABLE inventories ADD FOREIGN KEY (movie_id) REFERENCES movies (id) ; ALTER TABLE charges_rentals ADD FOREIGN KEY (rental_id) REFERENCES rentals (id) ; /* Create Triggers */ CREATE OR REPLACE TRIGGER TRI_academy_awards_id BEFORE INSERT ON academy_awards FOR EACH ROW BEGIN SELECT SEQ_academy_awards_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_academy_awards_movies_id BEFORE INSERT ON academy_awards_movies FOR EACH ROW BEGIN SELECT SEQ_academy_awards_movies_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_actors_id BEFORE INSERT ON actors FOR EACH ROW BEGIN SELECT SEQ_actors_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_actors_movies_id BEFORE INSERT ON actors_movies FOR EACH ROW BEGIN SELECT SEQ_actors_movies_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_charges_id BEFORE INSERT ON charges FOR EACH ROW BEGIN SELECT SEQ_charges_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_charges_rentals_id BEFORE INSERT ON charges_rentals FOR EACH ROW BEGIN SELECT SEQ_charges_rentals_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_customers_id BEFORE INSERT ON customers FOR EACH ROW BEGIN SELECT SEQ_customers_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_directors_id BEFORE INSERT ON directors FOR EACH ROW BEGIN SELECT SEQ_directors_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_directors_movies_id BEFORE INSERT ON directors_movies FOR EACH ROW BEGIN SELECT SEQ_directors_movies_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_distributors_id BEFORE INSERT ON distributors FOR EACH ROW BEGIN SELECT SEQ_distributors_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_inventories_id BEFORE INSERT ON inventories FOR EACH ROW BEGIN SELECT SEQ_inventories_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_movies_id BEFORE INSERT ON movies FOR EACH ROW BEGIN SELECT SEQ_movies_id.nextval INTO :new.id FROM dual; END; / CREATE OR REPLACE TRIGGER TRI_rentals_id BEFORE INSERT ON rentals FOR EACH ROW BEGIN SELECT SEQ_rentals_id.nextval INTO :new.id FROM dual; END; / /* Comments */ COMMENT ON COLUMN charges.charge_type IS 'standard_charge late_fee damaged_fee failure_to_rewind_fee other'; COMMENT ON COLUMN movies.movie_type IS 'suspense horror mystery comedy other';