Subject | Re: Insert Trigger which makes an Update if pk allready there possible? |
---|---|
Author | johnmancuk |
Post date | 2004-08-20T18:22:09Z |
Hia Helen,
Wouldn't it be better to say:
begin
insert ....
when somethinggoeswrong
begin
update ...
end
end
That way you can see through the transaction isolation (which exists
() doesn't). Or even better:
begin
update ...
if row_count = 0 then
insert ...
end
Which saves all that messing about with exception handling.
John
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@t...>
wrote:
Wouldn't it be better to say:
begin
insert ....
when somethinggoeswrong
begin
update ...
end
end
That way you can see through the transaction isolation (which exists
() doesn't). Or even better:
begin
update ...
if row_count = 0 then
insert ...
end
Which saves all that messing about with exception handling.
John
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@t...>
wrote:
> The SP is the CORRECT way to do it:
>
> CREATE PROCEDURE INS_OR_UPDATE (
> PK integer;
> VAL varchar(20))
> as
> begin
> if (exists (select PK from aTable
> where PK = :PK)) then
> update aTable
> set VAL = :VAL
> where PK = :PK;
> else
> insert into aTable (PK, VAL)
> values (:PK, :VAL);
> end
>