diff --git a/lab-2/music-store-app/sql/dummy_data.sql b/lab-2/music-store-app/sql/dummy_data.sql new file mode 100644 index 0000000000000000000000000000000000000000..6da5bca33bf2985c1819d0e3bf689caddcca932e --- /dev/null +++ b/lab-2/music-store-app/sql/dummy_data.sql @@ -0,0 +1,41 @@ +INSERT INTO Genre (name) +VALUES +('Reggae'), +('Funk and Soul'), +('Jazz'), +('Classical'), +('Electronic'), +('Pop'); + +INSERT INTO Band (name, genre_id) +('The Wailers', 0), +('The Aces', 0), +('The Beatles', 5); + +INSERT INTO Artist (first_name, last_name, band_id) +VALUES +('Bob', 'Marley', 0), +('Peter', 'Tosh', 0), +('Burning', 'Spear', NULL), +('Alton', 'Ellis', NULL), +('Gregory', 'Issacs', NULL), +('Desmond', 'Dekker', 4), +('John', 'Lennon', 3), +('Madonna', NULL, NULL); + +INSERT INTO Album (title, year, artist_id, price) +VALUES +('Soul Rebel', 1970, 0, 25.99 ), +('Catch A Fire', 1973, 0, 25.99 ), +('Natty Dread', 1974, 0, 20.99 ), +('Babylon By Bus', 1978, 0, 24.99 ), +('Night Nurse', 1982, 4, 17.99 ), +('Mr Issacs', 1982, 4, 9.99 ), +('Black and Dekker', 1980, 5, 19.99 ), +('Sunday Coming', 1970, 3, 15.99 ); + +INSERT INTO Track (title, album_id, track_number) +VALUES +('Sunday Coming', 7, 1), +('These Eyes', 7, 2), +('Hurting Me', 7, 3); diff --git a/lab-2/music-store-app/sql/schema.sql b/lab-2/music-store-app/sql/schema.sql index 0999a25249c969f95f7341aece23ef991e119a91..3b2bb7725c5f648441cf92fb2dd6b8dcd7507838 100644 --- a/lab-2/music-store-app/sql/schema.sql +++ b/lab-2/music-store-app/sql/schema.sql @@ -1,6 +1,6 @@ /* Delete existing tables in reverse order of creation so as not to violate any foreign key constraints */ -DROP TABLE IF EXISTS LineItem, Transaction, Customer, Track, Album, Artist, Act, Genre; +DROP TABLE IF EXISTS LineItem, Transaction, Customer, Track, Album, Artist, Band, Genre; /* Define table for genres */ CREATE TABLE Genre ( @@ -10,7 +10,7 @@ CREATE TABLE Genre ( ); /* Define table for storing act (i.e. a group or solo artist) */ -CREATE TABLE Act ( +CREATE TABLE Band ( id INT AUTO_INCREMENT, name VARCHAR(50) NOT NULL, genre_id INT, @@ -24,10 +24,10 @@ CREATE TABLE Artist ( id INT AUTO_INCREMENT, first_name VARCHAR(25) NOT NULL, last_name VARCHAR(25), - act_id INT NOT NULL, + band_id INT, PRIMARY KEY (id), - FOREIGN KEY (act_id) - REFERENCES Act (id) + FOREIGN KEY (band_id) + REFERENCES Band (id) ); /* Define table for storing albums */ @@ -35,9 +35,12 @@ CREATE TABLE Album ( id INT AUTO_INCREMENT, name VARCHAR(50) NOT NULL, year YEAR(4), + artist_id INT, compilation BOOLEAN NOT NULL DEFAULT 0, price DECIMAL(5, 2) unsigned NOT NULL, - PRIMARY KEY (id) + PRIMARY KEY (id), + FOREIGN KEY (artist_id) + REFERENCES Artist (id) ); @@ -45,11 +48,9 @@ CREATE TABLE Album ( CREATE TABLE Track ( id INT AUTO_INCREMENT, title VARCHAR(50) NOT NULL, - act_id INT NOT NULL, album_id INT NOT NULL, + track_number INT UNIQUE, PRIMARY KEY (id), - FOREIGN KEY (act_id) - REFERENCES Act (id), FOREIGN KEY (album_id) REFERENCES Album (id) );