Subject Re: [firebird-support] From Restriced to CASCADE on delete
Author Milan Babuskov
federonline wrote:
> There are views that use (are dependent on) those tables, so dropping
> the tables and recreating becomes non-trivial as well (for me).
>
> The metadata looks like this:
> CREATE TABLE DATA (
> MAC VARCHAR(32) NOT NULL,
> DATETIME_STAMP TIMESTAMP default NULL);
>
> /* Foreign key(s) */
>
> ALTER TABLE DATA ADD CONSTRAINT FK_DATA_SENSOR_MAC
> FOREIGN KEY (MAC) REFERENCES SENSOR(MAC)
> ON UPDATE RESTRICT ON DELETE RESTRICT;
>
> Is there an easy ALTER I can do to the FK to cascade my deletes??

Restrict is the default mode of operation, so simply do not include the
UPDATE/DELETE in the statement:

ALTER TABLE DATA ADD CONSTRAINT FK_DATA_SENSOR_MAC
FOREIGN KEY (MAC) REFERENCES SENSOR(MAC);

If you do want to cascade deletes and restrict updates:

ALTER TABLE DATA ADD CONSTRAINT FK_DATA_SENSOR_MAC
FOREIGN KEY (MAC) REFERENCES SENSOR(MAC);
ON DELETE CASCADE;

Any admin tool should generate these statements automatically for you
when you select the restrict option for FK.

--
Milan Babuskov
http://www.flamerobin.org