--
-- Sample for illustrating the tableset verify procedure available of cgadm
--

drop if exists table t2;
create table t2 ( c int, d string(30));

alter table t2 add check chk1 on c > 0;
alter table t2 add check chk2 on d != 'invalid';

drop if exists alias a1;
create alias a1 on t2 ( c as cx, d as dx );

drop if exists table t1;
create table t1 ( primary a int not null, b string(30));
create btree b2 on t1 ( b );

drop if exists table t3;
create table t3 ( primary x string(30) not null);

drop if exists table t4;
create table t4 ( primary y int not null);

alter table t2 add foreign key fk1 (c )  references t1(a);
alter table t2 add foreign key fk2 (d )  references t3(x);

insert into t1 values ( 1, 'XXX');
insert into t1 values ( 2, 'YYY');
insert into t1 values ( 3, 'ZZZ');

insert into t3 values ( 'XXX');
insert into t3 values ( 'YYY');
insert into t3 values ( 'ZZZ');

insert into t2 values ( 1, 'XXX');
insert into t2 values ( 2, 'YYY');
insert into t2 values ( 3, 'ZZZ');


drop if exists trigger tg1;
@
create trigger tg1 before insert on t1
begin
        -- while t1 in increasing, t4 is decreasing
        delete from t4 where y = a;   
end;
@

drop if exists table tdrop;
create table tdrop ( c int, d string(30));

drop if exists procedure p1;

@
create procedure p1(a in int)
begin
	insert into tdrop values ( :a, 'XXX');
end;
@

drop if exists view v1;
create view v1 as
select c from tdrop;

-- the drop of table tdrop should result in verify failure of view v1
drop table tdrop;
