我是 mysql 和在线论坛的新手,而且还是一些编程新手,请我尝试强制执行引用约束,每次我在 Dno 列和 Employee 表中插入或更新一个值(即 76)时,它即使它是引用 Department 表中没有匹配值的 PK Dnumber 的外键也可以工作。如何强制执行引用违规?
CREATE TABLE EMPLOYEE
( Fname VARCHAR(15) NOT NULL,
Minit CHAR,
Lname VARCHAR(15) NOT NULL,
Ssn CHAR(9) NOT NULL,
Bdate DATE,
Address VARCHAR(30),
Sex CHAR,
Salary DECIMAL(10,2),
Super_ssn CHAR(9),
Dno INT NOT NULL,
PRIMARY KEY (Ssn),
FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE(Ssn),
FOREIGN KEY (Dno) REFERENCES DEPARTMENT(Dnumber) );
CREATE TABLE DEPARTMENT
( Dname VARCHAR(15) NOT NULL,
Dnumber INT NOT NULL,
Mgr_ssn CHAR(9) NOT NULL,
Mgr_start_date DATE,
PRIMARY KEY (Dnumber),
UNIQUE (Dname),
FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn) );
--------------------------Example of the Update code------------------
UPDATE EMPlOYEE
SET Dno='12'
WHERE Fname='Sandra';