| 1 |
create table counties ( |
| 2 |
county varchar(30) not null primary key, |
| 3 |
country varchar(30) |
| 4 |
) engine=ndb; |
| 5 |
insert into counties values ('Berkshire','England'),('Shropshire','England'), |
| 6 |
('Oxfordshire','England'),('Buckinghamshire','England'),('Somewhere','Earth'); |
| 7 |
create table towns ( |
| 8 |
town varchar(30) not null primary key, |
| 9 |
county varchar(30) default "Somewhere", |
| 10 |
index county_county_index (county), |
| 11 |
constraint county_town foreign key (county) |
| 12 |
references counties(county) on delete set default on update restrict |
| 13 |
) engine=ndb; |
| 14 |
insert into towns values ('Maidenhead','Berkshire'),('Reading','Berkshire'), |
| 15 |
('Shrewsbury','Shropshire'),('Oxford','Oxfordshire'); |
| 16 |
delete from counties where county='Shropshire'; |
| 17 |
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`towns`, CONSTRAINT `county_town` FOREIGN KEY (`county`) REFERENCES `counties` (`county`) ON DELETE SET DEFAULT ON UPDATE RESTRICT) |
| 18 |
show warnings; |
| 19 |
Level Code Message |
| 20 |
Warning 1296 Got error 256 'Foreign key constraint violated: Referenced row exists' from NDB |
| 21 |
Error 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`towns`, CONSTRAINT `county_town` FOREIGN KEY (`county`) REFERENCES `counties` (`county`) ON DELETE SET DEFAULT ON UPDATE RESTRICT) |
| 22 |
drop table towns, counties; |