我创建了一个训练表并放入其中。
DDL
drop table company;
drop table employee;
drop table work;
drop table manages;
create table company
(company_name varchar(20) not null,
city varchar(10) not null,
primary key(company_name)
);
create table employee
(employee_name varchar(20) not null,
street varchar(20),
city varchar(10) not null,
primary key(employee_name),
foreign key(city) references company
on delete cascade
);
create table work
(employee_name varchar(20) not null,
company_name varchar(20) not null,
salary numeric(8,2) check (salary > 20000 and salary < 300000),
primary key(employee_name),
foreign key (company_name) references company
on delete cascade,
foreign key(employee_name) references employee
on delete set null
);
create table manages
(employee_name varchar(20) not null,
manager_name varchar(20) not null,
primary key(employee_name),
foreign key(employee_name) references employee
on delete set null
);
要满足的条件
-城市不得具有NULL值。
-薪水介于20,000和300,000之间
-公司信息被删除时,在职员工的信息也被删除。
和我的插入数据
delete from company;
delete from employee;
delete from work;
delete from manages;
insert into company values ('SAMSUNG', 'Seoul');
insert into company values ('LG', 'Daejeon');
insert into company values ('POSCO', 'Pohang');
insert into company values ('KIA', 'Gwangju');
insert into company values ('SK', 'Incheon');
insert into employee values ('Youngbin', 'S-1', 'Seoul');
insert into employee values ('Beomsu', 'S-1', 'Seoul');
insert into employee values ('Eunbin', 'S-2 ', 'Seoul');
insert into employee values ('Kyungmin', 'S-3', 'Seoul');
insert into employee values ('Yujeong', 'S-3', 'Seoul');
insert into employee values ('Beomchan', 'D-1', 'Daejeon');
insert into employee values ('Gwangyoung', 'D-2', 'Daejeon');
insert into employee values ('Yeonju', 'D-3', 'Daejeon');
insert into employee values ('Jisu', 'D-4', 'Daejeon');
insert into employee values ('Jeongmin', 'P-1', 'Pohang');
insert into employee values ('Heeyeon', 'P-2', 'Pohang');
insert into employee values ('Gunmin', 'P-3', 'Pohang');
insert into employee values ('Yeji', 'G-1', 'Gwangju');
insert into employee values ('Heenyeong', 'G-2', 'Gwangju');
insert into employee values ('Suhyeon', 'G-3', 'Gwangju');
insert into employee values ('Minju', 'I-1', 'Incheon');
insert into employee values ('Gitaek', 'I-2', 'Incheon');
insert into employee values ('Hayoung', 'I-3', 'Incheon');
insert into employee values ('Min', 'I-4', 'Incheon');
insert into wrok values('Youngbin', 'SAMSUNG', '290000');
insert into work values('Beomsu', 'SAMSUNG', '280000');
insert into work values('Eunbin', 'LG', '220000');
insert into work values('Kyungmin', 'KIA', '90000');
insert into work values('Yujeong', 'POSCO', '110000');
insert into work values('Beomchan', 'SK', '40000');
insert into work values('Gwangyoung', 'POSCO', '190000');
insert into work values('Yeonju', 'SK', '170000');
insert into work values('Jisu', 'LG', '60000');
insert into work values('Jeongmin', 'KIA', '140000');
insert into work values('Heeyeon', 'SAMSUNG', '210000');
insert into work values('Gunmin', 'KIA', '220000');
insert into work values('Yeji', 'LG', '180000');
insert into work values('Heenyeong', 'SAMSUNG', '120000');
insert into work values('Suhyeon', 'SK', '130000');
insert into work values('Minju', 'POSCO', '50000');
insert into work values('Gitaek', 'SK', '85000');
insert into work values('Hayoung', 'LG', '160000');
insert into work values('Min', 'SAMSUNG', '100000');
insert into manages values('Youngbin', null);
insert into manages values('Beomsu', 'Youngbin');
insert into manages values('Eunbin', null);
insert into manages values('Kyungmin', 'Gunmin');
insert into manages values('Gwangyoung', null);
insert into manages values('Yeonju', 'null');
insert into manages values('Jisu', 'Eunbin');
insert into manages values('Jeongmin', 'Gunmin');
insert into manages values('Heeyeon', 'Youngbin');
insert into manages values('Gunmin', null);
insert into manages values('Yeji', 'Eunbin');
insert into manages values('Heenyeong', 'Youngbin');
insert into manages values('Suhyeon', 'Yeonju');
insert into manages values('Minju', 'Gwangyoung');
insert into manages values('Gitaek', 'Yeonju');
insert into manages values('Hayoung', 'Eunbin');
insert into manages values('Min', 'Youngbin');
表是正常创建的,但是从公司后的插入数据,即将值放入员工数据时,会发生以下错误。
插入员工价值观('Youngbin','S-1','Seoul')错误-ORA-02291:违反完整性约束(SYSTEM.SYS_C007017)-找不到父键
创建表时是否设置了错误的值?我的桌子适合吗?
修改前应插入哪些数据? ..
谢谢您的阅读
我的版本-> oracle 11g
表COMPANY的主键是COMPANY_NAME,您已为其插入以下值:
表EMPLOYEE具有外键(city) references company
,这意味着EMPLOYEE.CITY中的值必须与COMPANY.COMPANY_NAME中的现有值匹配。
您正在尝试将'Soeul'插入EMPLOYEE.CITY。由于此值与COMPANY.COMPANY_NAME的任何值都不匹配,因此您会遇到约束冲突。