Subject | FOREIGN KEY constraint on possibly NULL field? |
---|---|
Author | zionemo |
Post date | 2006-04-11T20:23:33Z |
Hi,
please bear with me since I'm a relative newbie to databases and a
complete one to firbird.
This said let's go to the problem:
I should define a table where one field is *not* mandatory (so I do
not have the "NOT NULL" clause), but (if it exists) it should be a
reference to another table. I tried doing this via:
CREATE TABLE Editors
(
EditorID INTEGER NOT NULL,
Name VARCHAR(30) NOT NULL,
Comment BLOB,
CONSTRAINT Editors_C
PRIMARY KEY (EditorID, Name )
);
CREATE TABLE Characters
(
CharacterID INTEGER NOT NULL,
EditorID INTEGER,
Name VARCHAR(64) NOT NULL,
CONSTRAINT Characters_C
PRIMARY KEY ( CharacterID, Name ),
FOREIGN KEY ( EditorID ) REFERENCES Editors (EditorID)
);
... but I get an error stating I cannot have a FOREIGN KEY if the
field (Characters.EditorID) is not a NOT-NULL/UNIQUE field
("unsuccessful metadata update" / "could not find UNIQUE INDEX with
specified columns").
I think I missed some important point somewhere, but I have some
problems finding my way in the documentation available online.
Could someone point me in the right direction??
Thanks in Advance.
ZioNemo
please bear with me since I'm a relative newbie to databases and a
complete one to firbird.
This said let's go to the problem:
I should define a table where one field is *not* mandatory (so I do
not have the "NOT NULL" clause), but (if it exists) it should be a
reference to another table. I tried doing this via:
CREATE TABLE Editors
(
EditorID INTEGER NOT NULL,
Name VARCHAR(30) NOT NULL,
Comment BLOB,
CONSTRAINT Editors_C
PRIMARY KEY (EditorID, Name )
);
CREATE TABLE Characters
(
CharacterID INTEGER NOT NULL,
EditorID INTEGER,
Name VARCHAR(64) NOT NULL,
CONSTRAINT Characters_C
PRIMARY KEY ( CharacterID, Name ),
FOREIGN KEY ( EditorID ) REFERENCES Editors (EditorID)
);
... but I get an error stating I cannot have a FOREIGN KEY if the
field (Characters.EditorID) is not a NOT-NULL/UNIQUE field
("unsuccessful metadata update" / "could not find UNIQUE INDEX with
specified columns").
I think I missed some important point somewhere, but I have some
problems finding my way in the documentation available online.
Could someone point me in the right direction??
Thanks in Advance.
ZioNemo