Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE DATABASE medialib;
- CREATE TABLE Title (
- titleID int NOT NULL PRIMARY KEY,
- mediaID int NOT NULL,
- publisherID int NOT NULL,
- categoryID int NOT NULL,
- titleName varchar(255),
- publishYear year,
- entryDate date NOT NULL
- );
- CREATE TABLE Publisher (
- publisherID int NOT NULL PRIMARY KEY,
- publisherName VARCHAR(255)
- );
- CREATE TABLE Category (
- categoryID int NOT NULL PRIMARY KEY,
- categoryName VARCHAR(255)
- );
- CREATE TABLE Media (
- mediaID int NOT NULL PRIMARY KEY,
- mediaName VARCHAR(255)
- );
- ALTER TABLE Title
- ADD FOREIGN KEY (mediaID) REFERENCES media(mediaID),
- ADD FOREIGN KEY (categoryID) REFERENCES category(categoryID),
- ADD FOREIGN KEY (publisherID) REFERENCES publisher(publisherID);
- CREATE TABLE Contributor(
- contributorID int NOT NULL PRIMARY KEY,
- nationality VARCHAR(255),
- lastName VARCHAR(255),
- firstName VARCHAR(255)
- );
- CREATE TABLE DomesticContributor(
- domesticContributorID int NOT NULL PRIMARY KEY,
- contributorID int NOT NULL,
- streetAddress VARCHAR(255),
- city VARCHAR(255),
- state VARCHAR(255),
- zipCode VARCHAR(255) , -- Zip codes may be of varying length, and shouldn't be treated as numbers
- telephone VARCHAR(255), -- same applies to telephone numbers
- email VARCHAR(255)
- );
- ALTER TABLE domesticcontributor
- ADD FOREIGN KEY (contributorID) REFERENCES contributor(contributorID);
- CREATE TABLE NonDomesticContributor(
- nonDomesticContributorID int NOT NULL PRIMARY KEY,
- contributorID int NOT NULL,
- country VARCHAR(255),
- email VARCHAR(255),
- telephone VARCHAR(255),
- FOREIGN KEY (contributorID) REFERENCES Contributor(contributorID)
- );
- CREATE TABLE Title_Contributor(
- titleContributorID int NOT NULL PRIMARY KEY,
- contributorID int NOT NULL,
- titleID int NOT NULL,
- FOREIGN KEY (contributorID) REFERENCES Contributor(contributorID),
- FOREIGN KEY (titleID) REFERENCES Title(titleID)
- );
- CREATE TABLE Role(
- roleID int NOT NULL PRIMARY KEY,
- titleContributorID int NOT NULL,
- roleName VARCHAR(255),
- FOREIGN KEY (titleContributorID) REFERENCES title_contributor(titleContributorID)
- );
Add Comment
Please, Sign In to add comment