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