Db Design
Summary
Mapping EER
EER
Mappings
Super/Sub type
EER
Mapping
Weak Entity Type
EER
Mapping
SQL
EER
Mapping
Code
CREATE TABLE User(
Email varchar(50) NOT NULL,
FirstName varchar(50) NOT NULL,
LastName varchar(50) NOT NULL,
Password varchar(50) NOT NULL,
PRIMARY KEY (EMAIL));
CREATE TABLE RegularUser(
Email varchar(50) NOT NULL,
Sex char(1) NULL,
Birthdate datetime NULL,
CurrentCity varchar(50) NULL,
HomeTown varchar(50) NULL,
PRIMARY KEY (Email),
FOREIGN KEY (Email) REFERENCES `User` (Email));
CREATE TABLE AdminUser(
Email varchar(50) NOT NULL,
LastLogin datetime NULL,
PRIMARY KEY (Email),
FOREIGN KEY (Email) REFERENCES `User` (Email));
CREATE TABLE Interests(
Email varchar(50) NOT NULL,
Interest varchar(50) NOT NULL,
PRIMARY KEY (Email, Interests),
FOREIGN KEY (Email) REFERENCES RegularUser (Email));
More examples
CREATE TABLE Attend(
Email varchar(50) NOT NULL,
SchoolName varchar(50) NOT NULL,
YearGraduated int NULL,
UNIQUE (Email, SchoolName, YearGraduated), -- YearGraduated can be NULL so
-- this can't be a key.
FOREIGN KEY (Email) REFERENCES RegularUser (Email),
FOREIGN KEY (SchoolName) REFERENCES School (SchoolName));
CREATE TABLE Employment(
Email varchar(50) NOT NULL,
EmployerName varchar(50) NOT NULL,
JobTitle varchar(50) NOT NULL,
UNIQUE (Email, EmployerName, JobTitle),
FOREIGN KEY (Email) REFERENCES RegularUser (Email),
FOREIGN KEY (EmployerName) REFERENCES Employer (EmployerName));
Frienship
CREATE TABLE Friendship(
Email varchar(50) NOT NULL,
FriendEmail varchar(50) NOT NULL,
Relationship varchar(50) NOT NULL,
DateConnected datetime NULL,
PRIMARY KEY (Email, FriendEmail),
FOREIGN KEY (Email) REFERENCES RegularUser (Email),
FOREIGN KEY (FriendEmail) REFERENCES RegularUser (Email));
Abstract Code with SQL
for each $interest
INSERT INTO Interest (Email, Interest) VALUES ($Email, $Interest);
end for