diff --git a/insertStatements.sql b/insertStatements.sql new file mode 100644 index 0000000..7801834 --- /dev/null +++ b/insertStatements.sql @@ -0,0 +1,49 @@ +INSERT INTO Genre VALUES +('action', 1, 0, 0, 0, 0, 0, 0, 0), +('horror', 0, 1, 0, 0, 0, 0, 0, 0), +('comedy', 0, 0, 1, 0, 0, 0, 0, 0), +('suspense', 0, 0, 0, 1, 0, 0, 0, 0), +('adventure', 0, 0, 0, 0, 1, 0, 0, 0); + +INSERT INTO Films VALUES +('AAAAAAAA', 'The Great Gatsby', 'Guy is rich but unhappy', '2:23', 7, 'Comedy'), +('AAAAAAAB', 'American Psycho', 'Guy is rich but unhappy', '2:10', 8, 'Suspense'), +('AAAAAAAC', 'Batman', 'Guy is rich and fights crime while being unhappy', '2:10', 9, 'Action'), +('AAAAAAAD', 'The Mist', 'Spooky things occur after the mist rolls in', '2:02', 6, 'Horror'), +('AAAAAAAE', 'Shrek', 'An ogre goes on a quest', '1:33', 10, "Adventure"); + +INSERT INTO Actors VALUES +('AAAAAAAA', 'Leonardo DiCaprio', 'M', '38', 'Big moviestar, been in many films'), +('AAAAAAAB', 'Christian Bale', 'M', '46', 'Big moviestar, been in many films'), +('AAAAAAAC', 'Adam West', 'M', '75', 'Big moviestar, been in many films'), +('AAAAAAAD', 'Thomas Jane', 'M', '55', 'Big moviestar, been in many films'), +('AAAAAAAE', 'Mike Myers', 'M', '65', 'Big moviestar, been in many films'); + +INSERT INTO Directors VALUES +('AAAAAAAA', 'Andrew Adamson', 'M', '38', 'Big hollywood director, directed many films'), +('AAAAAAAB', 'Vicky Jenson', 'F', '35', 'Big hollywood director, directed many films'), +('AAAAAAAC', 'Baz Luhrmann', 'M', '30', 'Big hollywood director, directed many films'), +('AAAAAAAD', 'Mary Harron', 'F', '51', 'Big hollywood director, directed many films'), +('AAAAAAAE', 'Frank Darabont', 'M', '48', 'Big hollywood director, directed many films'); + +INSERT INTO Actor_has_films VALUES +('AAAAAAAA', 'AAAAAAAA'), +('AAAAAAAB', 'AAAAAAAB'), +('AAAAAAAC', 'AAAAAAAC'), +('AAAAAAAD', 'AAAAAAAD'), +('AAAAAAAE', 'AAAAAAAE'); + +INSERT INTO Genre_has_films VALUES +('Action', 'AAAAAAAC'), +('Comedy', 'AAAAAAAA'), +('Horror', 'AAAAAAAD'), +('Suspense', 'AAAAAAAB'), +('Adventure', 'AAAAAAAE'); + +INSERT INTO Directs VALUES +('AAAAAAAA', 'AAAAAAAA'), +('AAAAAAAB', 'AAAAAAAB'), +('AAAAAAAC', 'AAAAAAAC'), +('AAAAAAAD', 'AAAAAAAD'), +('AAAAAAAE', 'AAAAAAAE'); + diff --git a/relationalModel3NF.png b/relationalModel3NF.png new file mode 100644 index 0000000..8851024 Binary files /dev/null and b/relationalModel3NF.png differ diff --git a/selectStatements.sql b/selectStatements.sql new file mode 100644 index 0000000..cad4fdd --- /dev/null +++ b/selectStatements.sql @@ -0,0 +1,72 @@ +SELECT genre, films_id FROM Genre_has_films; +SELECT name FROM Directors; +SELECT title FROM Films; + +SELECT genre FROM Genre WHERE action = 1; +SELECT actor_id FROM Actor_has_films WHERE films_id = 'AAAAAAAA'; +SELECT title FROM Films WHERE films_id = 'AAAAAAAA'; + +SELECT name FROM Actors +WHERE age > 50 +ORDER BY age; + +SELECT director_id, age FROM Directors +WHERE gender = 'F' +ORDER BY age; + +SELECT COUNT(actor_id) FROM Actors; +SELECT MAX(age) FROM Directors; + +SELECT name, gender, MIN(age) FROM Actors +WHERE gender = 'F'; + +SELECT director_id, COUNT(*) FROM Directors +WHERE gender = 'M'; + +SELECT title, COUNT(*) FROM Films +GROUP BY title; + +SELECT gender, AVG(age) FROM Directors +GROUP BY gender; + +SELECT duration, COUNT(*) FROM Films +GROUP BY reviews +HAVING reviews > 8; + +SELECT name, age, gender FROM Directors +GROUP BY gender +HAVING age > AVG(age); + +SELECT * FROM Actor_has_films INNER JOIN Actors ON Actor_has_films.actor_id = Actors.actor_id; + +SELECT Directors.name, Directs.films_id FROM Directors, Directs +WHERE Directors.director_id = Directs.director_id; + +SELECT * FROM Actor_has_films +LEFT OUTER JOIN Films +ON Actor_has_films.films_id = Films.films_id +LEFT OUTER JOIN Actors +ON Actor_has_films.actor_id = Actors.actor_id; + +SELECT * FROM Directs +CROSS JOIN Actor_has_films +CROSS JOIN Genre_has_films; + +SELECT * FROM Actor_has_films +LEFT OUTER JOIN Films +ON Actor_has_films.films_id = Films.films_id +LEFT OUTER JOIN Actors +ON Actor_has_films.actor_id = Actors.actor_id +LEFT OUTER JOIN Directs +ON Films.films_id = Directs.films_id; + +SELECT * FROM Films +CROSS JOIN Actor_has_films +CROSS JOIN Directs +CROSS JOIN Actors; + + + + + + diff --git a/sqlCreateStatements.sql b/sqlCreateStatements.sql new file mode 100644 index 0000000..842878b --- /dev/null +++ b/sqlCreateStatements.sql @@ -0,0 +1,66 @@ +CREATE TABLE Genre ( + genre varchar(25) NOT NULL, + action bool, + horror bool, + comedy bool, + suspense bool, + adventure bool, + crime bool, + fiction bool, + animated bool, + PRIMARY KEY (genre) +); + +CREATE TABLE Films ( + films_id char(8) NOT NULL, + title varchar(25), + description varchar(255), + duration varchar(4), + reviews int, + genre varchar(25) NOT NULL, + PRIMARY KEY (films_id), + FOREIGN KEY (genre) REFERENCES Genre(genre) +); + +CREATE TABLE Actors ( + actor_id char(8) NOT NULL, + name varchar(20), + gender CHAR, + age int, + bio varchar(255), + PRIMARY KEY (actor_id) +); + +CREATE TABLE Directors ( + director_id char(8) NOT NULL, + name varchar(20), + gender CHAR, + age int, + bio varchar(255), + PRIMARY KEY (director_id) +); + +CREATE TABLE Actor_has_films ( + actor_id char(8) NOT NULL, + films_id char(8) NOT NULL, + PRIMARY KEY (actor_id, films_id), + FOREIGN KEY (actor_id) REFERENCES Actors(actor_id), + FOREIGN KEY (films_id) REFERENCES Films(films_id) +); + +CREATE TABLE Genre_has_films ( + genre varchar(25) NOT NULL, + films_id char(8) NOT NULL, + PRIMARY KEY (genre, films_id), + FOREIGN KEY (genre) REFERENCES Genre(genre), + FOREIGN KEY (films_id) REFERENCES Films(films_id) +); + +CREATE TABLE Directs ( + films_id char(8) NOT NULL, + director_id char(8) NOT NULL, + PRIMARY KEY (films_id, director_id), + FOREIGN KEY (films_id) REFERENCES Films(films_id), + FOREIGN KEY (director_id) REFERENCES Director(director_id) +); +