drop table c;
drop table p;

create table p (
       id int not null, primary key(id)
);
create table c (
       id int not null,
       pid int not null,
       primary key(id),
       foreign key(pid) references p(id) deferrable
);

begin transaction;
set constraints all deferred;

insert into c values (1,1);
insert into c values (2,1);
insert into c values (3,1);

insert into c values (4,2);
insert into c values (5,2);
insert into c values (6,3);

insert into c values (7,3);
insert into c values (8,3);
insert into c values (9,3);

insert into p values (1);
insert into p values (2);
insert into p values (3);

commit;

begin transaction;
set constraints all deferred;

delete from c;
delete from p;

insert into c values (1,1);
insert into c values (2,1);
insert into c values (3,1);

insert into c values (4,2);
insert into c values (5,2);
insert into c values (6,3);

insert into c values (7,3);
insert into c values (8,3);
insert into c values (9,3);

insert into p values (1);
insert into p values (2);
insert into p values (3);


commit;