Answered step by step
Verified Expert Solution
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 char string with the format USAHR
Where:
Characters : represent the country of the producer: eg USA, BRA, CAN, IND, ENG, JAP
Characters : represent the year of the movie: eg
Characters : represent an identifier of the movie genre: eg HR for Horror, CM for Comedy
Characters digit sequence
when characters from are the same as a previous entry, the sequence increments by one.
For example, if the mId USAHR already exists, the next movie to be input with the
country: USA, year: and genre: HR should have the mId USAHR
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 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 character string with the format HH: MM eg::
Any date field in the schema should be stored as a date object, not just as character strings.
The genreid and year 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 attributes that make up the primary key if any exists for each of the relations.
List the attributes that make up the foreign keysif 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 constraintsrestrictions 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 relationtable
The movie rental store only uses movies released in or later.
numrentals, times a movie has been rented, does not allow null values, the DEFAULT value when
populating should be
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.
populate the customer and director tables with at least three entries each make up the data values
populate the movie table with at least movies make up the data values; values should meet all
corresponding constraints. Pay attention to the director IDs
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.
Check your data and verify that all the conditions above have been met.
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 HWOUTPUTYOURNAME
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started