| 1 |
-- source include/have_ndb.inc |
| 2 |
|
| 3 |
create table parent ( |
| 4 |
a int primary key auto_increment, |
| 5 |
b int, |
| 6 |
c int, |
| 7 |
unique(b) using hash, |
| 8 |
index(c)) engine = ndb; |
| 9 |
|
| 10 |
create table child ( |
| 11 |
a int primary key auto_increment, |
| 12 |
b int, |
| 13 |
c int, |
| 14 |
unique(b) using hash, |
| 15 |
index(c)) engine = ndb; |
| 16 |
|
| 17 |
### |
| 18 |
### UK vs UK |
| 19 |
### |
| 20 |
alter table child add constraint fkname foreign key (b) references parent(b) on delete restrict on update cascade; |
| 21 |
|
| 22 |
insert into parent values (1,1,1), (2,2,2); |
| 23 |
insert into child values (1,1,1),(2,2,2); |
| 24 |
|
| 25 |
begin; |
| 26 |
update parent set b = 1 where a = 1; |
| 27 |
select * from child order by 1,2,3; |
| 28 |
rollback; |
| 29 |
|
| 30 |
begin; |
| 31 |
update parent set b = null where a = 1; |
| 32 |
select * from child order by 1,2,3; |
| 33 |
rollback; |
| 34 |
|
| 35 |
begin; |
| 36 |
update parent set b = 3 where a = 1; |
| 37 |
select * from child order by 1,2,3; |
| 38 |
rollback; |
| 39 |
|
| 40 |
delete from child; |
| 41 |
delete from parent; |
| 42 |
|
| 43 |
alter table child drop foreign key fkname; |
| 44 |
|
| 45 |
### |
| 46 |
### UK vs OI |
| 47 |
### |
| 48 |
alter table child add constraint fkname foreign key (c) references parent(b) on delete restrict on update cascade; |
| 49 |
|
| 50 |
insert into parent values (1,1,1),(2,2,2); |
| 51 |
insert into child values (1,1,1),(2,2,2),(3,3,1),(4,4,2); |
| 52 |
|
| 53 |
begin; |
| 54 |
update parent set b = null where a = 1; |
| 55 |
select * from child order by 1,2,3; |
| 56 |
rollback; |
| 57 |
|
| 58 |
begin; |
| 59 |
update parent set b = 3 where a = 1; |
| 60 |
select * from child order by 1,2,3; |
| 61 |
rollback; |
| 62 |
|
| 63 |
delete from child; |
| 64 |
delete from parent; |
| 65 |
|
| 66 |
alter table child drop foreign key fkname; |
| 67 |
|
| 68 |
drop table parent, child; |