Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a script, one step at a time, to generate the DB schema of the movie rental database. Test the partial results by inspecting the

Write a script, one step at a time, to generate the DB schema of the movie rental database. Test the partial
results by inspecting the tables in SQLDeveloper. Do not proceed to the next step until you have the previous one
working correctly.
Part I Define the MOVIE rental database.
a. Use the following database schema to create a script that generates and populates the movie rental
database. You must write the script to create the tables for this schema.
b. Requirements
- The movie IDs should be a 16-char string with the format USA-2003-HR-0001
Where:
Characters 1-3: represent the country of the producer: e.g., USA, BRA, CAN, IND, ENG, JAP
Characters 5-8: represent the year of the movie: e.g.,2003
Characters 10-11: represent an identifier of the movie genre: e.g., HR for Horror, CM for Comedy
Characters 13-16,4-digit sequence
when characters from 1-12 are the same as a previous entry, the sequence increments by one.
For example, if the mId USA-2003-HR-0001 already exists, the next movie to be input with the
country: USA, year: 2003, and genre: HR should have the mId USA-2003-HR-0002.
You DONT have to generate these mIds automatically, but the data you input manually must
comply with this requirement.
- Customer and director IDs are represented by a 9-digit code (as well as producerID).
- Please choose a proper max length for first names, last names, and movie titles. Check this movie title as
a reference to pick your max length.
- dob represents the date of birth of the customer or director, rented indicates the date a movie was
rented and returndate indicates when the movie is returned. If the movie has not been returned, the
value of returndate is unknown (hint: the value should be null).
- duration is a fixed 5-character string with the format HH: MM, e.g.02:32,04:43.
- Any date field in the schema should be stored as a date object, not just as character strings.
- The genreid and year (4-digit integer) of the movie must be consistent with the corresponding mId.
c. Define the primary keys and foreign keys as indicated in the schema above. It will help if you:
- List the attribute(s) that make up the primary key (if any exists) for each of the relations.
- List the attribute(s) that make up the foreign key(s)(if any exist) in each of the relations.
Hint: you will have to create DIRECTOR before MOVIE, and MOVIE and CUSTOMER before RENTAL.
d. Include the following constraints/restrictions on your table definitions:
- Emails should include the @ character (only the @ should be check in the constraint)
- No two emails can be equal in the same relation/table.
- The movie rental store only uses movies released in 1950 or later.
- num_rentals, times a movie has been rented, does not allow null values, the DEFAULT value when
populating should be 0.
e. To avoid conflicts during repeated runs of your script, start your script file with DROP TABLE commands for
all four tables (hint: to prevent foreign key violation errors, put them in reverse order of the creation of the
tables).
f. Run your script and look at the columns and constraints of each table to verify that they have been created
correctly before continuing your work.
Part II Populate the database.
- Populate the tables in the proper order to avoid referential errors.
1) populate the customer and director tables with at least three entries each (make up the data values)
2) populate the movie table with at least 4 movies (make up the data values; values should meet all
corresponding constraints. Pay attention to the director IDs)
3) populate the RENTAL table for at least five movie rentals (make up the data; the values should meet all
corresponding constraints.)
every movie shouldve been rented at least once.
Every director should be used at least once.
Every customer should have rented at least one movie. Some should have rented at least two.
At least one customer should have a rental yet to be returned.
4) Check your data and verify that all the conditions above have been met.
5) Assume that the movie rental place only has one copy of each movie, so the dates for two rentals of the
same movie should NOT overlap. Do not create constraints for this, just make sure your data meet this
condition.
Note: this definition of the database prevents a customer from renting the same movie more than once.
What would you change to fix this? You dont need to answer this question for the assignment!
Part III Displaying the content of your tables.
- Display ALL the content of each table by adding SELECT statements at the very end of your script.
- Add a single COMMIT; statement at the end of your script.
- Run the complete script and save the complete contents of the script output window, including the
displayed data, to a text file. (Clear the script output window first so that only the output of the last run
of your script is displayed and saved.) Save it as HW02_OUTPUT_YOURNAME

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions