Question: CREATE TABLE album ( id SERIAL, title VARCHAR ( 1 2 8 ) UNIQUE, PRIMARY KEY ( id ) ; CREATE TABLE track ( id
CREATE TABLE album
id SERIAL,
title VARCHAR UNIQUE,
PRIMARY KEY id
;
CREATE TABLE track
id SERIAL,
title VARCHAR
len INTEGER, rating INTEGER, count INTEGER,
albumid INTEGER REFERENCES albumid ON DELETE CASCADE,
UNIQUEtitle albumid
PRIMARY KEYid
;
DROP TABLE IF EXISTS trackraw;
CREATE TABLE trackraw
title TEXT, artist TEXT, album TEXT, albumid INTEGER,
count INTEGER, rating INTEGER, len INTEGER;
We will ignore the artist field for this assignment and focus on the manytoone relationship between tracks and albums.
If you run the program multiple times in testing or with different files, make sure to empty out the data before each run.
Load this CSV data file into the trackraw table using the lcopy command. Then write SQL commands to insert all of the distinct albums into the album table creating their primary keys and then set the albumid in the trackraw table using an SQL query like:
UPDATE trackraw SET albumid SELECT
album.id FROM album. WHERE album.title trackraw.album;
Then use a INSERT SELECT statement to copy the corresponding data from the trackraw table to the track table, effectively dropping the artist and album text fields.
grade this assignment, the autograder will run a query like this on your database and look for the data it expects to see:
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
