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(128) UNIQUE,
PRIMARY KEY (id)
;
CREATE TABLE track (
id SERIAL,
title VARCHAR(128),
len INTEGER, rating INTEGER, count INTEGER,
album_id INTEGER REFERENCES album(id) ON DELETE CASCADE,
UNIQUE(title, album_id),
PRIMARY KEY(id)
;
DROP TABLE IF EXISTS track_raw;
CREATE TABLE track_raw
(title TEXT, artist TEXT, album TEXT, album_id INTEGER,
count INTEGER, rating INTEGER, len INTEGER);
We will ignore the artist field for this assignment and focus on the many-to-one 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 track_raw 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 album_id in the track_raw table using an SQL query like:
UPDATE track_raw SET album_id =(SELECT
album.id FROM album. WHERE album.title = track_raw.album);
Then use a INSERT ... SELECT statement to copy the corresponding data from the track_raw table to the track table, effectively dropping the artist and album text fields.
grade this assignment, the auto-grader will run a query like this on your database and look for the data it expects to see:
 CREATE TABLE album ( id SERIAL, title VARCHAR(128) UNIQUE, PRIMARY KEY

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!