Предположим, у вас есть еще две таблицы, а именно socialClubs
и clubMembership
, и необходимые ограничения (primary
и foreign
), определенные ниже:
SQL> create table socialClubs( -- parent(look-up) table for "clubMembership" table.
2 id int primary key,
3 name varchar2(500)
4 );
Table created
SQL> create table clubMembership( -- parent table for "member" table.
2 id int primary key,
3 club_id int,
4 constraint fk_cmmb_sc_id
5 foreign key(club_id)
6 references socialClubs(id)
7 );
Table created
SQL> create table member(
2 mem_id int primary key,
3 mem_address varchar2(500),
4 address_type varchar2(10),
5 effective_date date,
6 end_date date,
7 adress varchar2(500),
8 city varchar2(50),
9 zip_code varchar2(10),
10 phone_number number(15),
11 last_name varchar2(50),
12 first_name varchar2(50),
13 constraint fk_cmmb_mem_id
14 foreign key(mem_id)
15 references clubMembership(id)
16 );
Table created
SQL> insert into socialClubs values(1,'Mathematics');
1 row inserted
SQL> insert into member
2 (mem_id,
3 mem_address,
4 address_type,
5 effective_date,
6 end_date,
7 adress,
8 city,
9 zip_code,
10 phone_number,
11 last_name,
12 first_name)
13 values
14 (19889218,
15 191166765,
16 'Z2',
17 date'2013-08-01',
18 date'2016-05-07',
19 '45 NEWYORK',
20 'ATLANTIC NY',
21 011101,
22 2012922341,
23 'BOB',
24 'GUY');
ORA-02291: integrity constraint (ASKIMEMUR.FK_CMMB_MEM_ID) violated - parent key not found
поднимает ORA-02291 ошибка ,
, поскольку в таблице clubMembership для member_id 19889218 из member * нет (родительской) записи1019 * таблица, которая имеет встроенное определение constraint fk_cmmb_mem_id foreign key(mem_id) references clubMembership(id)
.
Так что вставьте необходимый member_id в clubMembership table и продолжайте без проблем:
SQL> insert into clubMembership values(19889218,1);
1 row inserted
SQL> insert into member
2 (mem_id,
3 mem_address,
4 address_type,
5 effective_date,
6 end_date,
7 adress,
8 city,
9 zip_code,
10 phone_number,
11 last_name,
12 first_name)
13 values
14 (19889218,
15 191166765,
16 'Z2',
17 date'2013-08-01',
18 date'2016-05-07',
19 '45 NEWYORK',
20 'ATLANTIC NY',
21 011101,
22 2012922341,
23 'BOB',
24 'GUY');
1 row inserted
SQL> commit;
Commit complete