Commit 2295787d authored by Sorrel Harriet's avatar Sorrel Harriet

Adding example sql files for lab 2

parents
/* Statement to insert some records in the artist table */
INSERT INTO sharr003_recordstore.artist (id, first_name, last_name)
VALUES
(NULL, 'Bob', 'Marley'),
(NULL, 'Peter', 'Tosh'),
(NULL, 'Burning', 'Spear'),
(NULL, 'Alton', 'Ellis'),
(NULL, 'Gregory', 'Issacs');
INSERT INTO sharr003_recordstore.record (id, title, artist_id, genre, year, price)
VALUES
(NULL, 'Catch A Fire', NULL, 'Reggae', 1973, 20.99 ),
(NULL, 'Sunday Coming', NULL, 'Reggae', 1970, 15.99 );
SELECT first_name, last_name FROM artist;
SELECT title FROM record
WHERE year = 1973
AND genre = "Reggae";
/* Make sure tables don't exist before creation */
DROP TABLE IF EXISTS record, artist;
/* Define table for storing artists */
CREATE TABLE artist (
id INT AUTO_INCREMENT,
first_name VARCHAR(50),
last_name VARCHAR(50),
PRIMARY KEY(id)
);
/* Define table for storing records (products) */
CREATE TABLE record (
id INT AUTO_INCREMENT,
title VARCHAR(50),
artist_id INT,
genre TINYTEXT,
year YEAR(4),
price DECIMAL(10, 2) unsigned,
PRIMARY KEY (id),
FOREIGN KEY (artist_id)
REFERENCES artist (id)
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment