Dennis Volodomanov wrote:
> Is it possible to create such an AFTER INSERT trigger that updates
> certain fields in a table based on the actual data being inserted?
>
> Let's say:
>
> CREATE TABLE abc(TypeID INTEGER)
> CREATE TABLE abcCount(TypeCountA, TypeCountB)
>
> CREATE TRIGGER CountTypeA AFTER INSERT ON abc /* when abc.TypeID == 1
> */ BEGIN
> UPDATE abcCount SET TypeCountA=TypeCountA+1; END
>
> CREATE TRIGGER CountTypeB AFTER INSERT ON abc /* when abc.TypeID == 2
> */ BEGIN
> UPDATE abcCount SET TypeCountB=TypeCountB+1; END
create trigger CountTypeA after insert on abc
when new.TypeId=1
begin
update abcCount set TypeCountA = TypeCountA + 1;
end;
create trigger CountTypeB after insert on abc
when new.TypeId=2
begin
update abcCount set TypeCountB = TypeCountB + 1;
end;
Or with a single trigger:
create trigger CountType after insert on abc
begin
update abcCount set
TypeCountA = TypeCountA + (new.TypeID = 1),
TypeCountB = TypeCountB + (new.TypeID = 2);
end;
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users