Basically I'd like to know the difference between using REFERENCES with or without a foreign key.
I have these 2 examples:
CREATE TABLE Employee
(
id INT,
name VARCHAR(50),
birthYear INT,
boss INT REFERENCES Employees(id),
worksAt INT NOT NULL REFERENCES Department(id) ON DELETE CASCADE,
PRIMARY KEY (id,worksAt)
);
Example 2:
CREATE TABLE Department
(
id INT PRIMARY KEY,
name VARCHAR(50),
numberOfEmployees INT,
location INT NOT NULL,
country INT NOT NULL,
manager INT,
FOREIGN KEY (location,country) REFERENCES Location(locId,countryId),
UNIQUE KEY (manager)
);
What I'm asking here is why does the second example use the FOREIGN KEY keyword while the first one merely uses REFERENCES.
Also, the first one seems to reference itself (I think the s in Employees is a mistake) If so, why does it use REFERENCES if it's referencing itself?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…