· 9 years ago · Nov 22, 2016, 12:26 AM
1/*****************************/
2/* PROJECT 8 SCHEMA CREATION */
3/*****************************/
4drop table if exists album cascade;
5drop table if exists artist cascade;
6
7create table artist (
8 id serial,
9 name text NOT NULL,
10 primary key(id));
11
12create table album (
13 id serial,
14 artist_id integer,
15 title text NOT NULL,
16 year numeric(4),
17 primary key (id),
18 foreign key (artist_id) references artist (id));
19
20
21/******************/
22/* DATA MIGRATION */
23/******************/
24
25/* populate artist table */
26insert into artist (name)
27select distinct artist_name from project7;
28
29/* populate album table */
30insert into album (artist_id, title, year)
31select distinct
32 a.id,
33 p.album_title,
34 p.album_year
35from
36 artist a,
37 project7 p
38where a.name = p.artist_name;