Subject Re: [firebird-support] REPLACE command
Author Martijn Tonies
> >>>Is there a REPLACE command avaible at Firebird? With the same function
> >
> > Like in mySQL:
> >
> >>No but you can write a simple BEFORE INSERT trigger to do the same
> >>thing, and it would be a much standard way.
> >
> > I'm not sure if I understand how a BEFORE INSERT trigger comes into the
> > picture?
>
> CREATE TRIGGER ... BEFORE INSERT ...
> AS
> IF EXISTS (SELECT * FROM TABLE WHERE PK = NEW_PKVALUE) THEN
> DELETE FROM TABLE WHERE PK = NEW_PKVALUE;
>
> And that's all. I know the syntax isn't 100% correct, but you get the
> point. Of course, if you don't want it to work that way all the time,
> you can write also simple stored procedure to do it.

Ah, of course :-)

You know - I bet I know why MySQL has a REPLACE... As it doesn't have
FKs, it doesn't have cascading delete FKs and you can easily delete a master
row. With Firebird, however, you would "replace" the row, but you would run
into problems with FKs.

Another - I think better - command would be:

INSERT_OR_UPDATE :-)


With regards,

Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com