作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
DROP TABLE if exists employee;
CREATE TABLE employee (
fname varchar(15) not null,
minit varchar(1),
lname varchar(15) not null,
ssn char(9),
bdate date,
address varchar(50),
sex char,
salary decimal(10,2),
superssn char(9),
dno int(4),
primary key (ssn),
foreign key (superssn) references employee(ssn)
-- foreign key (dno) references department(dint)
);
DROP TABLE if exists department;
CREATE TABLE department (
dname varchar(25) not null,
dint int(4),
mgrssn char(9) not null,
mgrstartdate date,
primary key (dint),
unique (dname),
foreign key (mgrssn) references employee(ssn)
);
ALTER TABLE employee ADD (
foreign key (dno) references department(dint)
);
DROP TABLE if exists dept_locations;
CREATE TABLE dept_locations (
dint int(4),
dlocation varchar(15),
primary key (dint,dlocation),
foreign key (dint) references department(dint)
);
DROP TABLE if exists project;
CREATE TABLE project (
pname varchar(25) not null,
pint int(4),
plocation varchar(15),
dnum int(4) not null,
primary key (pint),
unique (pname),
foreign key (dnum) references department(dint)
);
DROP TABLE if exists works_on;
CREATE TABLE works_on (
essn char(9),
pno int(4),
hours decimal(4,1),
primary key (essn,pno),
foreign key (essn) references employee(ssn),
foreign key (pno) references project(pint)
);
DROP TABLE if exists dependent;
CREATE TABLE dependent (
essn char(9),
dependent_name varchar(15),
sex char,
bdate date,
relationship varchar(8),
primary key (essn,dependent_name),
foreign key (essn) references employee(ssn)
);
最佳答案
错误出现在这一行ALTER TABLE员工ADD (...
请编辑并使其看起来像:
ALTER TABLE employee ADD
foreign key (dno) references department(dint);
有一些不必要的括号。
关于mysql - 错误 1451 (2300) : Cannot delete or update a parent row: a foreign key constraint fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39864654/
我是一名优秀的程序员,十分优秀!