/**************************************************************************************/
/* File:        demo16                                                                */
/* Project:     ATSQL2 : Table creation with queries                                  */
/* Author:      Andreas Steiner                                                       */
/* Date:        10-20-1998                                                            */
/* Results:                                                                           */
/**************************************************************************************/

create table test(a integer, b char(20));

insert into test values (1, 'test1');
insert into test values (2, 'test2');


create table vt_test(c integer, d char(20)) as validtime;

validtime period [1981-1985) insert into vt_test values (1, 'test1');
validtime period [1984-1988) insert into vt_test values (1, 'test1');
validtime period [1990-forever) insert into vt_test values (2, 'test2');


/* Creating Tables : */
/* ================ */

create table test1 as select * from test;
create table test11 as select a from test;
create table test12 as select a, b from test;

create table test2 as validtime select * from vt_test;
create table test21 as validtime select c as y from vt_test;
create table test22(w) as validtime select c as y from vt_test;

create table test3(a, b) as select * from test;

create table test4(x, y) as validtime select * from vt_test;

create table test5 as (validtime select * from vt_test) (period);

create table test6(x, y) as (validtime select * from vt_test) (period);

create table test7 as
  validtime 
    select * 
    from   test2, test4, test5;

create table test7 (a, b, c, d, e, c) as
  validtime 
    select * 
    from   test2, test4, test5;

create table test7 (a, b, c, d, e, f) as
  validtime 
    select * 
    from   test2, test4, test5;

create table test8 as
  validtime 
    (select * 
     from   vt_test, test4, test5) (period);

create table test8 (a, b, c, d, e, f) as
  validtime 
    (select * 
     from   vt_test, test4, test5) (period);



/* Querying Views : */
/* ================ */

select * from test1;
select a from test11;
select a, b from test12;

select * from test2;
validtime select * from test2;
validtime select * from test21;
validtime select * from test22;

select * from test3;

select * from test4;
validtime select * from test4;

validtime select * from test5;

validtime select * from test6;

validtime select * from test7;

validtime select * from test8;




/* Remove Tables/Views : */
/* ===================== */

drop table test1;
drop table test11;
drop table test12;
drop table test2;
drop table test21;
drop table test22;
drop table test3;
drop table test4;
drop table test5;
drop table test6;
drop table test7;
drop table test8;

drop table test;
drop table vt_test;

