Question: Question 1 - A library is setting up a database with the following relational schema: Book ( isbn , title , author ) Copy (
Question A library is setting up a database with the following relational schema:
Bookisbntitle author
Copyisbnserialnumber, weight, bookcase
A book must have an isbn and a title. Several copies of each book can be present in the library, each with a unique serial number, a weight in grams. Each bookcase has a number. The following constraints apply to every change to the database:
Every book has a unique value for isbn.
For every copy C there exists a book that has Cs isbn. A copy cannot be added to the database if a book with the copy's isbn does not exists in the table Book.
If the isbn of a book in the database changes, then the isbn of copies
of that book should also change so those copies continue to belong to the same book
The removal of a book must result in all its copies being deleted.
Give the SQL create statements for Book and Copy such that the above requirements are fulfilled. Use sensible data types or each attribute. Use key constraints and associated actions. Do not use triggers.
NB foreign keys need to be enabled explicitly in SQLite using the commandPRAGMA foreignkeys ON;Without this option enabled, SQLite will ignore foreign keys, which will make it difficult to properly test your queries.
Hide hint for Question
Remember that foreign key constraints are stated as follows:
FOREIGN KEY xxREFERENCES TyyON eaON ea
where xxand yyare attribute names; T is a table name; eeare events deleteupdateand aaare actions set null, set default, no action, cascadeActions might or might not be deferrable.
Question
Give a sequence of two insert statements that violate constraint above Every book has a unique value for isbn
Question
Let's assume that the book table contains the following row and no other rows:
A first course in Database Systems', 'Jennifer Widom'
Give an SQL statement that violates constraint
Question
Let's assume that we have two copies of Jennifer Widom's book, iethe table Copy has the following two rows:
Give an SQL update statement that shows that condition is handled correctly.
Question
Listen
For your database, give an SQL statement that shows that constraint is handled correctly.
Question
Add a constraint to Copy or recreate Copy with the added constraintthat makes sure that books never weigh less than grams and never more than grams
Hint for Question
Create the table with an additional "CHECK" constraint. In PostgreSQL you can use 'ALTER TABLE' to add the constraint
Question
Write an assertion that makes sure that somewhere in our library there exists a book copy written by 'Jennifer Widom'
NB PostgreSQL and SQLite do not support assertions yet. PostgreSQL does check the syntax of your query.
hint for Question
Tip: Test the SQL query inside your assertion separately on your database.
Question
Create an assertion that states that the total amount of book copies in our library should not exceed billion grams.
Question
Create an assertion that makes sure that no bookcase in our library has more than grams of books.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
