Question: Problem Description Consider the following SQL tables: CREATE TABLE person ( name VARCHAR ( 1 0 0 ) , email VARCHAR ( 1 0 0
Problem Description
Consider the following SQL tables:
CREATE TABLE person
name VARCHAR
email VARCHAR
work INTEGER,
hobbies INTEGER,
sleep INTEGER
;
CREATE TABLE hobbies
email VARCHAR
hobby VARCHAR
hours INTEGER
;
Problem points: Rewrite the person schema using ALTER TABLE statements to satisfy
the following constraints:
A None of the five columns can be NULL
B email contains at least one @
C No two emails are the same
D work, hobbies, and sleep are all
E work, hobbies, sleep should sum up to at most hours in a day
F The defaults for work, sleep, and hobbies are
Hint: consider using the LIKE operator.
Problem points: Now redeclare the table hobbies using CREATE TABLE so that:
A email is a foreign key to the email column in the person table
B email, hobby, hours are not NULL
C hours is a positive integer
Problem points: Obviously, person. hobbies needs to be the sum of hobbies. hours for
all hobbies for the person.
A First write a SELECT statement that checks whether this constraint is met. Remember
that you can put a boolean expression in the SELECT clause to display true or false for
some condition.
B Explain whether what you wrote in A can be a CHECK constraint in PostgreSQL.
Answer questions
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
