Subject | Re: [firebird-support] Delete all rows of a table |
---|---|
Author | Helen Borrie |
Post date | 2005-02-27T11:28:42Z |
At 11:11 AM 27/02/2005 +0000, you wrote:
FOREIGN KEY (PARENT_ID)
REFERENCES CATEGORY(CATEGORY_ID)
ON DELETE SET NULL;
;
./hb
>I have a question about deleting all the rows from a table. The table..provided you define the appropriate delete behaviour.
>represents a hierarchy of categories so that the end result is a tree
>of categories.
>
>When I try to delete all the rows from the table using "delete from
>category" I get a foreign key viloation. I don't believe this should
>happen as the "delete from" should delete all the data in the table
>and should not care about foreign keys within the same table.
>
>I know that MSSQL allows it, and I think Oracle and DB2 also allow it.
>Is there a way around this?See below.
>Thanks,ALTER TABLE CATEGORY ADD CONSTRAINT PARENT_CAT
>Bryan
>
>CREATE TABLE CATEGORY
>(
> CATEGORY_ID INTEGER NOT NULL,
> PARENT_ID INTEGER,
> NAME VARCHAR(100),
> CONSTRAINT CAT_PK PRIMARY KEY (CATEGORY_ID)
>);
FOREIGN KEY (PARENT_ID)
REFERENCES CATEGORY(CATEGORY_ID)
ON DELETE SET NULL;
;
>INSERT INTO CATEGORY VALUES (1, NULL, 'Category 1');Yup, that's how referential integrity is intended to work.
>INSERT INTO CATEGORY VALUES (2, 1, 'Category 1');
>DELETE FROM CATEGORY;
>
>The "delete from" results in a foreign key violation.
./hb