Re: Organisation tree - prevent deletion of parent organisation
That's great! Now it works! If I replace ON DELETE CASCADE with ON DELETE
RESTRICT or I completely omnit it, it does exactly what I needed!
CREATE TABLE Organisations (
Id INT UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY,
ParentId INT UNSIGNED ZEROFILL,
Name VARCHAR(50) NOT NULL UNIQUE
) ENGINE = InnoDB;
ALTER TABLE Organisations ADD CONSTRAINT C_Organisations_ParentId
FOREIGN KEY (ParentId)
REFERENCES Organisations(Id);
Thank you a lot all!
"subtenante" <zzsubtenantezz@gmail.com> píse v diskusním príspevku
news:lq5923tc7m2o6o5vsoin0kb47bp4giart3@4ax.com...
> On Tue, 17 Apr 2007 11:14:11 +0200, "Vojta" <ryvo@centrum.cz> wrote:
>
>
>>ALTER TABLE MemberTree ADD CONSTRAINT C_MemberTree_1
>>FOREIGN KEY (ParentId) REFERENCES MemberTree(Id) ON DELETE CASCADE; (*)
>
> Yes.
> The problem is in your ON DELETE CASCADE.
> This means that if you delete a row, all its children will be erased
> too.
> So simply take it out of the definition, it should work fine.
|