Re: Organisation tree - prevent deletion of parent organisation
On Tue, 17 Apr 2007 09:15:05 +0100, "Sean"
<sean.anderson@[nospam]oakleafgroup.biz> wrote:
>On your delete statements you could have:
>
>DELETE FROM ORGANISATIONS
>WHERE ID NOT IN
>(
> SELECT PARENTID
> FROM ORGANISATIONS
>)
>AND ID = n
>
>Sean
Well, adding a FOREIGN KEY constraint on parentid (foreign key on the
id primary key column), might work better and without having to do
tricks in the delete statements : if you try to delete a row with an
id used as parentid somewhere, you will have a constraint failure and
the delete will not proceed.
|