diff --git a/lab-4/music-store-app/sql/dummy_data.sql b/lab-4/music-store-app/sql/dummy_data.sql new file mode 100644 index 0000000000000000000000000000000000000000..382b3739cc5405b6b9a17c92e6c9e1c3065d1ed5 --- /dev/null +++ b/lab-4/music-store-app/sql/dummy_data.sql @@ -0,0 +1,66 @@ +INSERT INTO Genre (name) +VALUES +('Reggae'), +('Funk and Soul'), +('Jazz'), +('Classical'), +('Electronic'), +('Pop'); + +INSERT INTO Band (name, genre_id) +VALUES +('The Wailers', 1), +('The Aces', 2), +('The Beatles', 6); + +INSERT INTO Artist (first_name, last_name, band_id) +VALUES +('Bob', 'Marley', 1), +('Peter', 'Tosh', 1), +('Burning', 'Spear', NULL), +('Alton', 'Ellis', NULL), +('Gregory', 'Issacs', NULL), +('Desmond', 'Dekker', 2), +('John', 'Lennon', 3), +('Madonna', NULL, NULL); + +INSERT INTO Album (upc, title, release_year, artist_id, compilation, price, genre_id) +VALUES +('123425364732', 'Soul Rebel', 1970, 1, FALSE, 25.99, 1 ), +('017263547261', 'Catch A Fire', 1973, 1, 0, 25.99, 1 ), +('018263526272', 'Natty Dread', 1974, 1, 1, 20.99, 1 ), +('018273527273', 'Babylon By Bus', 1978, 1, 'FALSE', 24.99, 1 ), +('491827364626', 'Night Nurse', 1982, 5, TRUE, 17.99, 1 ), +('018276272828', 'Mr Issacs', 1982, 5, 0, 9.99, 1 ), +('018273662728', 'Black and Dekker', 1980, 6, 0, 19.99, 1 ), +('726517237627', 'Sunday Coming', 1970, 4, TRUE, 15.99, 1 ), +('018274372722', 'Imagine', 1971, 7, NULL, 11.99, 6 ), +('018273727287', 'Like a Virgin', 1984, 8, 1, 9.99, 6 ); + +INSERT INTO Track (name, album_upc, track_number) +VALUES +('Sunday Coming', '726517237627', 1), +('Imagine', '018274372722', 1), +('Material Girl', '018273727287', 1), +('Angel', '018273727287', 2), +('Crippled Inside', '018274372722', 2), +('These Eyes', '726517237627', 2), +('Hurting Me', '726517237627', 3); + +INSERT INTO Customer (username, email_address, password, first_name, last_name, address_1, address_2, postcode) +VALUES +('sharr003', 's.harriet@gold.ac.uk', 'SOME_HASHED_VALUE', 'Sorrel', 'Harriet', '12 Fake Street', 'London', 'SE140PL'), +('ktack001', 'k.tackie@hotmail.com', 'SOME_HASHED_VALUE', 'Kobi', 'Tackie', '12 Fake Street', 'London', 'SE140PL'); + +INSERT INTO Transaction (customer_id, delivery) +VALUES +(1, 'next working day'), +(1, 'first class'), +(2, 'second class'); + +INSERT INTO LineItem (trans_id, album_upc, quantity) +VALUES +(1, '018273727287', 1), +(2, '018273727287', 1), +(3, '491827364626', 1), +(1, '018274372722', 2); diff --git a/lab-4/music-store-app/sql/schema_norm.sql b/lab-4/music-store-app/sql/schema_norm.sql index a50644a8821871a62497e0f47d7bc74a6b4b4935..8d8f95a71d483f2b36e56d2f5773b183858e654f 100644 --- a/lab-4/music-store-app/sql/schema_norm.sql +++ b/lab-4/music-store-app/sql/schema_norm.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, Band, Genre; +DROP TABLE IF EXISTS Rating, Wish, LineItem, Transaction, Customer, Track, Album, Artist, Band, Genre; /* Define table for genres */ CREATE TABLE Genre ( @@ -27,7 +27,10 @@ CREATE TABLE Artist ( id INT AUTO_INCREMENT, first_name VARCHAR(25) NOT NULL, last_name VARCHAR(25), - PRIMARY KEY (id) + band_id INT, + PRIMARY KEY (id), + FOREIGN KEY (band_id) + REFERENCES Band (id) ); /* Define table for storing albums */ @@ -35,10 +38,13 @@ CREATE TABLE Album ( upc CHAR(12), title VARCHAR(50) NOT NULL, release_year YEAR(4), + artist_id INT, compilation BOOLEAN NOT NULL DEFAULT 0, price DECIMAL(5, 2) unsigned NOT NULL, genre_id INT, PRIMARY KEY (upc), + FOREIGN KEY (artist_id) + REFERENCES Artist (id), FOREIGN KEY (genre_id) REFERENCES Genre (id) ); @@ -107,8 +113,8 @@ CREATE TABLE LineItem ( Compile wishlists from this data. */ CREATE TABLE Wish ( customer_id INT, - album_upc INT, - PRIMARY KEY (customer_id, album_id), + album_upc CHAR(12) NOT NULL, + PRIMARY KEY (customer_id, album_upc), FOREIGN KEY (customer_id) REFERENCES Customer(id) ON DELETE CASCADE, @@ -122,7 +128,7 @@ CREATE TABLE Rating ( customer_id INT NOT NULL, album_upc CHAR(12) NOT NULL, score TINYINT unsigned NOT NULL, - PRIMARY KEY (customer_id, album_id), + PRIMARY KEY (customer_id, album_upc), FOREIGN KEY (customer_id) REFERENCES Customer(id) ON DELETE CASCADE,