Shabacka

Database Creation SQL code for MediaLib Project

Nov 23rd, 2020 (edited)
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.15 KB | None | 0 0
  1. CREATE DATABASE medialib;
  2.  
  3. CREATE TABLE Title (
  4.     titleID int NOT NULL PRIMARY KEY,
  5.     mediaID int NOT NULL,
  6.     publisherID int NOT NULL,
  7.     categoryID int NOT NULL,
  8.     titleName varchar(255),
  9.     publishYear year,
  10.     entryDate date NOT NULL
  11. );
  12.  
  13. CREATE TABLE Publisher (
  14.     publisherID int NOT NULL PRIMARY KEY,
  15.     publisherName VARCHAR(255)
  16. );
  17.  
  18. CREATE TABLE Category (
  19.     categoryID int NOT NULL PRIMARY KEY,
  20.     categoryName VARCHAR(255)
  21. );
  22.  
  23. CREATE TABLE Media (
  24.     mediaID int NOT NULL PRIMARY KEY,
  25.     mediaName VARCHAR(255)
  26. );
  27.  
  28. ALTER TABLE Title
  29. ADD FOREIGN KEY (mediaID) REFERENCES media(mediaID),
  30. ADD FOREIGN KEY (categoryID) REFERENCES category(categoryID),
  31. ADD FOREIGN KEY (publisherID) REFERENCES publisher(publisherID);
  32.  
  33. CREATE TABLE Contributor(
  34.     contributorID int NOT NULL PRIMARY KEY,
  35.     nationality VARCHAR(255),
  36.     lastName VARCHAR(255),
  37.     firstName VARCHAR(255)
  38. );
  39.  
  40. CREATE TABLE DomesticContributor(
  41.     domesticContributorID int NOT NULL PRIMARY KEY,
  42.     contributorID int NOT NULL,
  43.     streetAddress VARCHAR(255),
  44.     city VARCHAR(255),
  45.     state VARCHAR(255),
  46.     zipCode VARCHAR(255) , -- Zip codes may be of varying length, and shouldn't be treated as numbers
  47.     telephone VARCHAR(255), -- same applies to telephone numbers
  48.     email VARCHAR(255)
  49. );
  50.  
  51. ALTER TABLE domesticcontributor
  52. ADD FOREIGN KEY (contributorID) REFERENCES contributor(contributorID);
  53.  
  54. CREATE TABLE NonDomesticContributor(
  55.     nonDomesticContributorID int NOT NULL PRIMARY KEY,
  56.     contributorID int NOT NULL,
  57.     country VARCHAR(255),
  58.     email VARCHAR(255),
  59.     telephone VARCHAR(255),
  60.     FOREIGN KEY (contributorID) REFERENCES Contributor(contributorID)
  61. );
  62.  
  63. CREATE TABLE Title_Contributor(
  64.     titleContributorID int NOT NULL PRIMARY KEY,
  65.     contributorID int NOT NULL,
  66.     titleID int NOT NULL,
  67.     FOREIGN KEY (contributorID) REFERENCES Contributor(contributorID),
  68.     FOREIGN KEY (titleID) REFERENCES Title(titleID)
  69. );
  70.  
  71. CREATE TABLE Role(
  72.     roleID int NOT NULL PRIMARY KEY,
  73.     titleContributorID int NOT NULL,
  74.     roleName VARCHAR(255),
  75.     FOREIGN KEY (titleContributorID) REFERENCES title_contributor(titleContributorID)
  76. );
Add Comment
Please, Sign In to add comment