Subject | Re: [ib-support] check syntax |
---|---|
Author | Lucas Franzen |
Post date | 2002-01-25T23:20:53Z |
> One more question:The constraint will allow that.
>
> what happens if the user - after having choosen a value for ParentID -
> wants to change the field into a blank (undefined) value ?
>
> Will the constraint still allow that ?
Whether you can set the ParentID to NULL or not is depending on how the
field in the child table has been defined (nullable or not null).
The constraint will just take care that you can't have values in the
child table that have no corresponding entry in the parent table.
One more thing for defining foreign key constraints.
If you want all children to be deleted when the parent record is deleted
you can define it like:
alter table child
add constraint <constraint_name> foreign key (ParentID)
references parent (ParentID)
ON DELETE CASCADE.
If you want it to get null, you can use: ON DELETE SET NULL
Luc.