i have a project about constructing a database of a newspaper in mysql . newspaper_leaflet entity has a column "publisher" that references in the email of the entity of the publisher and the email of the publisher references in the email of the entity of employees. i expect when i insert values into newspaper_leaflet in which the email(email is the primary key for the entity of publisher and for the entity of employees) doesnt exist in publisher entity ,to throw me an error ,altough that doesnt happen , and i dont understand why. i could make a stored procedure to solve this problem ,i guess, but i dont understand how the constraint works if it doesnt protect the table from inserting different emails from that ,that exists in publisher entity.
CREATE TABLE Employee(
email VARCHAR(30),
employment_date DATE,
name VARCHAR(20),
surname VARCHAR(30),
salary FLOAT,
PRIMARY KEY(email)
);
CREATE TABLE Publisher( email VARCHAR(30),
PRIMARY KEY(email),
CONSTRAINT publishertoemployee
FOREIGN KEY (email) REFERENCES Employee (email)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE Leaflet(
leaflet_number INT,
newspaper_name VARCHAR(20),
numberofpages INT Default 30,
newspaper_leaflets INT,
leaflets_notsold INT,
publish_date DATE,
leaflet_publisher VARCHAR(30),
PRIMARY KEY (leaflet_number,newspaper_name),
CONSTRAINT publisherofnp
FOREIGN KEY (leaflet_publisher) REFERENCES Publisher (email),
CONSTRAINT npleafetconnection
FOREIGN KEY (newspaper_name) REFERENCES Newspaper (newspaper_name)
ON DELETE CASCADE
ON UPDATE CASCADE
);
this is my git if you want to see all the db https://github.com/kwstasmel/SQL-Project PS: I am a newbie ,every polite advise will be appreciated.