Am Mittwoch, 21. Januar 2004 19:03 schrieb Dennis Cote:
[...]
> --create some base tables to test
> create table t1 (a, b);
> insert into t1 values (1, 10);
> create table t2 (a, c);
> insert into t2 values (1, 100);
[...]
> /******* Now a better way ***********/
>
> --create view with column name aliases
> create view v2 as select
>         t1.a as a,
>         t1.b as b,
>         t2.c as c
> from t1 join t2 using (a);
>
> --show the column names
> select * from v1;
> a|b|c
> 1|10|100
> 2|20|222
> 3|30|300
>
> -- now the triggers work as expected
> create trigger up_v2_c instead of update of c on v2
>         begin
>                 update t2 set c = new.c where a = new.a;
>         end;
> create trigger in_v2 instead of insert on v2
>         begin
>                 insert into t1 values (new.a, new.b);
>                 insert into t2 values (new.a, new.c);
>         end;
>
> --test the triggers
> insert into v2 values (4, 40, 400);
> insert into v2 values (5, 50, 500);
> select * from v2;
> a|b|c
> 1|10|100
> 2|20|222
> 3|30|300
> 4|40|400
> 5|50|500
>
> update v2 set c = 444 where a = 4;
> select * from v2;
> a|b|c
> 1|10|100
> 2|20|222
> 3|30|300
> 4|40|444
> 5|50|500
> sqlite>
>
> I hope this helps.

That's it! You helped a lot! Many Thanks!
Although it is much work because the view has got many columns that like to 
have an alias now...

Regards

Tim Krah


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to