Advertisement
Edzhevit

MinionsSQL

May 15th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.06 KB | None | 0 0
  1. CREATE SCHEMA movies;
  2.  
  3. CREATE TABLE directors (
  4. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  5. director_name VARCHAR(45),
  6. notes TEXT
  7. );
  8.  
  9. CREATE TABLE genres (
  10. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  11. genre_name VARCHAR(45),
  12. notes TEXT
  13. );
  14.  
  15. CREATE TABLE categories (
  16. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  17. category_name VARCHAR(45),
  18. notes TEXT
  19. );
  20.  
  21. CREATE TABLE movies (
  22. id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
  23. title VARCHAR(45),
  24. director_id INT NOT NULL,
  25. copyright_year DATE NOT NULL,
  26. length DOUBLE,
  27. genre_id INT NOT NULL,
  28. category_id INT NOT NULL,
  29. rating DOUBLE,
  30. notes TEXT
  31. );
  32.  
  33. ALTER TABLE movies
  34. ADD CONSTRAINT director_fk FOREIGN KEY (director_id) REFERENCES directors(id);
  35.  
  36. ALTER TABLE movies
  37. ADD CONSTRAINT genre_fk FOREIGN KEY (genre_id) REFERENCES genres(id);
  38.  
  39. ALTER TABLE movies
  40. ADD CONSTRAINT category_fk FOREIGN KEY (category_id) REFERENCES categories(id);
  41.  
  42. INSERT INTO directors (id, director_name, notes)
  43.  VALUES(1, "Daglov", "Strict Director"),
  44.        (2, "Pashov", "Gentle Director"),
  45.        (3, "Manol", "Good"),
  46.        (4, "Stamat", "Excellent"),
  47.        (5, "Granat", "BOMB");
  48.        
  49. INSERT INTO genres (id, genre_name, notes)
  50. VALUES(10, "drama", "notes"),
  51.       (11, "comedy", "notes"),
  52.       (12, "action", "notes"),
  53.       (13, "fantasy", "notes"),
  54.       (14, "horror", "notes");
  55.      
  56. INSERT INTO categories (id, category_name, notes)
  57. VALUES(20, "Thriller", "notes"),
  58.       (21, "Science Fiction", "notes"),
  59.       (22, "Romance", "notes"),
  60.       (23, "Adventure", "notes"),
  61.       (24, "Documentary", "notes");
  62.      
  63. INSERT INTO movies (id, title, director_id, copyright_year, length, genre_id, category_id, rating, notes)
  64. VALUES(100, "Curious Case Of Benjamin Button", 1, '2013-01-01', 120, 10, 22, 10, "Very good movie"),
  65.       (101, "Avengers", 2, '2018-01-01', 180, 12, 21, 10, "Best Movie"),
  66.       (102, "Game of Thrones", 3, '2019-01-01', 100, 13, 23, 100, "My favourite series"),
  67.       (103, "LOTR", 4, '2002-02-02', 220, 13, 23, 10, "All time best"),
  68.       (104, "Matrix", 1, '2002-03-03', 180, 12, 21, 10, "WOW");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement