Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Project 3: Data Manipulation Language (DML), Part 2 of 2

1. (2 points)

a.) Delete all rentals from your database.

DELETE FROM (Select * from rentals);

b.) Via an SQL query, retrieve the 5 valid rows from your table of customers
from Project 2.

Select * from customer order by cust_id;

c.) Then, via another query, update the street address of one of your 5 customers
using their account numbers (you can simply “hardcode” this is the
command from visual inspection of your table of customers.

Update customer Set street =’Greenhills Street’ Where cust_id = ‘C074’;

Update customer Set street =’Kingswel Street’ Where cust_id = ‘C049’;

Update customer Set street =’Margut Street’ Where cust_id = ‘C202’;

Update customer Set street =’Miguel Street’ Where cust_id = ‘C210’;

Update customer Set street =’Evergreen Street’ Where cust_id = ‘C011’;

d.) Then delete one of your other 5 customers using his or her name (“hardcode”
name in command after table inspection).

DELETE FROM (Select * from customer where lastname = ‘Smith’);

DELETE FROM (Select * from customer where lastname = ‘Jones’);

DELETE FROM(Select * from customer where lastname = ‘Carlo’);

DELETE FROM(Select * from customer where lastname = ‘AZI’);


DELETE FROM(Select * from customer where lastname = ‘WILLIAMS’);

e.) Then add 6 new customers with a mixture of zip codes.

INSERT INTO customer(cust_id,firstname,middle_init,last_name,house_no,


street,city_town,province,state,country,zip_code,age)VALUES(‘C049’,’John’,’F’,
‘Jones’,’056’,’Samba’,’Odenton’,’Quilid’,’MD’,’India’,’21113’,47),
(‘C001’,’Bert’,’T’,’Cain’,’304’,’Hue’,’Marinet’,’Quanto’,’MD’,’New
York’,’2336’,’24’),
(‘C002’,’Peter’,’F’,’Joseph’,’220’,’Case’,’Caides’,’Sentro’,’NY’,’New
York’,’9933’,’45’),
(‘C003’,’Hubert’,’Q’,’Jamesworth’,’332’,’Samba’,’Odento’,’Quilid’,’MD’,’India’,’21
113’,’34’),
(‘C004’,’John’,’T’,’Smith’,’0001’,’Muhan’,’Adelphi’,’MD’,’India’,’20002’,’28’),
(‘C005’,’Maria’,’D’,’Holand’,’7777’,’Cairo’,’Adelphi’,’MD’,’India’,’2444’,’20’);
COMMIT;

f.) Then, via a single query, retrieve only the account numbers, last names, cities
and zip codes for all 10 customers, sorted by zip code and then account
number.

SELECT cust_id, last_name, city_town, zip_code FROM customer Order by


zip_code;

Show the SQL you use and the Oracle response (data and feedback) to the SQL
directly after the SQL.

2. (3 points)

a) Add 5 more movies (now 10 total with those of Project 2) 20 more videos
(now 30 total with those Project 2) with a mixture of movie title and types
(e.g. westem, romance, comedy). Add data to other tables as needed for
referential integrity and to provide a good sample of actor, actress, director
and award data.

INSERT INTO movie(movie_id, movie_title, type, run_length, actors,


rental_price,director, award, year_released,rating)VALUES
(‘M0191’,’A Beautiful Life’,’Drama’,’81’,’Debi Mazar’,4.12,’Alejandro
Chomski’,’’,’2008’,’7.1’),
(‘M0192’,’Delgo’,’Animation’,’90’,’Freddie Prinze Jr.’, 4.00, ‘Mark F. Adler’, ‘’,
‘2008’,’7.2’),
(‘M0193’,’Del Toh Baccha Hai Ji’,’138’,’ Tisca Chopra’, 5.00, ‘Madhur Bhandarkar’,’ 2011’,
‘5.9’),
(‘M0193’,’GANTZ’,’131’,’ Kenichi Matsuyama’, 4.00, ‘Shinsuke Sato’, ‘2011’, ‘6.3’),
(‘M0194’,’Good Burger’,’96’,’ Kel Mitchell’, 4.00, ‘Brian Robbins’,’1997’, ‘5.1’);

b) Retrieve all 10 movies, showing title, movie ID, type, running length, rating,
year released, and all actors, sorted in ascending order by movie title.

Select * from movie order by movie_title;

c) Via a single query, retrieve those video renting (i.e., daily rental price) for
under $4.00, showing video ID, distributor name, wholesale purchase cost
from distributor, and current daily rental price to customers, sorted by
descending rental price and ascending video id within rental price.

Select * from movie, customer, distributor, dist_delivery, rental order by


movie.rental_price DESC, movie_id ASC;

Show the SQL you used and the Oracle responses (data and feedback) to the SQL
directly after each SQL statement.

3. (5 points) (Note that this step involves day-to-day OLTP)

a) Process 5 rental transactions on a single day (i.e. the “first” day) where your
customer 1 rent 1, customer 2 rent 2 videos, 3 rent 3, 4 rent 4, 5 rent 5 (You
can simply “hardcode” the customer account and video id number into these
commands from a visual inspection of your table)

Customer 1
Insert into rental (rental_id, cust_id, movie_id, no_of_copy, date_rented,
date_due)VALUES(‘R0001’,’C049’,’M0102’,1,to_date(‘01/03/00’,’mm/dd/yy
yy’),to_date(‘01/06/00’,’mm/dd/yyyy’));

Customer 2
Insert into rental(rental_id,cust_id, movie_id, no_of_copy, date_rented,
date_due)VALUES(‘R0002’,’C074’,’M050’,1,to_date(‘01/03/00’,’mm/dd/yyy
y’),to_date(‘01/06/00’,’mm/dd/yyyy’)),
(‘R0002’,’C074’,1,to_date(‘01/03/00’,’mm/dd/yyyy’),to_date(‘01/06/00’,’mm
/dd/yyyy’));

Customer 3
Insert into rental(rental_id,cust_id, movie_id, no_of_copy, date_rented,
date_due) VALUES(‘R0003’, ’C0202’, ’M0180’,1, todate(‘01/03/00’,
‘mm/dd/yyyy’),to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0003’,’C0202’,’M0190’,1,to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0003’,’C0202’,’M0191’,1,to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(’01/06/00’,’mm/dd/yyyy’));

Customer 4
Insert into rental(rental_id, cust_id, movie_id, no_of_copy, date_rented,
date_due)VALUES( ‘R0004’, ’C001’, ’M0192’, 1,
to_date(‘01/03/00’,’mm/dd/yyyy’),to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0004’, ‘C001’, ‘M0193’, 1, to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0004’, ‘C001’, ‘M0194’, 1, to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0004’, ‘C001’, ‘M0195’, 1, to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’));

Customer 5
Insert into rental(rental_id, cust_id, movie_id, no_of_copy, date_rented,
date_due)VALUES( ‘R0005’, ’C002’, ’M0196’, 1,
to_date(‘01/03/00’,’mm/dd/yyyy’),to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0005’, ‘C002’, ‘M0197’, 1, to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0005’, ‘C002’, ‘M0198’, 1, to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0005’, ‘C002’, ‘M0199’, 1, to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’),
(‘R0005’, ‘C002’, ‘M0200’, 1, to_date(‘01/03/00’,’mm/dd/yyyy’),
to_date(‘01/06/00’,’mm/dd/yyyy’));

b) On the next day, customer 3 returns all 3 videos and rents 3 more.

Update rental set


c)
4.

You might also like