Question

create table books (title text primary key,pubdate text,publisher text,publishercity text,scope text); create table publishers (publisherName text,founded...

create table books (title text primary key,pubdate text,publisher text,publishercity text,scope text);
create table publishers (publisherName text,founded date,founderName text[],headquarters text);
insert into books values
        ('the gremlins', 1943, 'random house', 'new york', 'children'),
        ('sometime never: a fable for supermen', 1948, 'charles scribner''s sons', 'new york', 'adult'),
        ('james and the giant peach', 1961, 'alfred a. knopf', 'new york', 'children'),
        ('charlie and the chocolate factory', 1964, 'alfred a. knopf', 'new york', 'children')
      
 insert into publishers(publisherName, founded, founderName, headquarters) values
        ('random house', 'Jan 1, 1927', '{bennett cerf, donald klopfer}'::Text[], 'new york City'),
        ('charles scribner''s sons', 'Jan 1, 1846', '{charles scribner i, isaac d. baker}'::Text[], 'new york'),
        ('alfred a. knopf', 'Jan 1, 1915', '{alfred a. knopf sr.}'::Text[], 'new york'),
        ('jonathan cape', 'Jan 1, 1921', '{herbert jonathan cape, wren howard}'::text[], 'london'),
     
select ('[' || 
(select string_agg(
'{' ||
        '"title" : "' || title || '", ' ||
        '"pubyear" : ' || pubdate || ', ' ||
        '"publisher" : "' || publisher || '", ' ||
        '"publishercity" : "' || publishercity || '", ' ||
        '"scope" : "' || scope || '", ' ||
        '"publisherName" : "' || publisherName || '", ' ||
        '"founded" : "' || founded || '", ' ||
        '"headquarters" : "' || headquarters || '", ' ||
        '"founders" : ' || substring('' ||json_build_array(founderName), 2, char_length('' ||json_build_array(founderName)) - 2) 
|| '}'
, ',') from books left outer join publishers on publisher = publishername) || ']')::jsonb 
into jsonbooks;

Do not use the books table or the publishers table in any of the queries you write. Queries which use either of these two tables will not receive credit. You must use the jsonbooks table in your queries.

  1. Explain how this data is denormalized (In other words: the table where each row is it’s own book is not in 3NF. Why?)

  2. Write a query that returns the titles of all books written before 1980.

Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This data is not in 3NF because it is having transitive dependencies, that is if a non- key attribute then there is a change in other non- key attributes. In the data given if non -key attribute like headquarters text change then corresponding publisher details may also change and this contradicts the property of 3NF that there should not be any transition dependencies. This data is also not in 2NF where only single column primary key should be there. Title cannot be the primary key as there may be two different books with same titles.

QUERY:

select title

from jsonbooks

where year ( founded ) < 1980 ;

Add a comment
Know the answer?
Add Answer to:
create table books (title text primary key,pubdate text,publisher text,publishercity text,scope text); create table publishers (publisherName text,founded...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MYSQL: Question: 1.Using a function, what are the lowest price books found in paperback? Only return...

    MYSQL: Question: 1.Using a function, what are the lowest price books found in paperback? Only return the lowest price books. Display the book code as ‘Book Code’, the book title as ‘Title’, author name concatenated (first last) as ‘Author Name’ and price as ‘Price’. Insert your snip of the query and resultset together here. 2. Display the number of publishers by city.   Display the city as ‘City’ and the number of publishers in that city as ‘Number of Publishers’. Insert...

  • MYSQL Questions: 1.For every author, display the number of books written by that author that is...

    MYSQL Questions: 1.For every author, display the number of books written by that author that is carried by Henry Books. Display the author number as ‘Author Number’, author name concatenated (first last) as ‘Author Name’, and the total number of books written by the author as ‘Number of Titles by Author’. List in descending order by author number. Limit the output to 10 rows. Insert your snip of the query and resultset together here. 2.Using a function, what are the...

  • How would you use this stored procedure to change the price of any copy of book 0180 whose format...

    How would you use this stored procedure to change the price of any copy of book 0180 whose format is paperback to $10.95? using MYSQL 8.0 Command line Client This is the database script for the homework above CREATE DATABASE HENRY; USE HENRY; CREATE TABLE AUTHOR (AUTHOR_NUM DECIMAL(2,0) PRIMARY KEY, AUTHOR_LAST CHAR(12), AUTHOR_FIRST CHAR(10) ); CREATE TABLE BOOK (BOOK_CODE CHAR(4) PRIMARY KEY, TITLE CHAR(40), PUBLISHER_CODE CHAR(3), TYPE CHAR(3), PRICE DECIMAL(4,2), PAPERBACK CHAR(1) ); CREATE TABLE BRANCH (BRANCH_NUM DECIMAL(2,0) PRIMARY KEY,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT