Subject | Re: [firebird-support] Problems with primary key not working |
---|---|
Author | Dany M |
Post date | 2006-03-27T22:35:34Z |
stab_bergbom wrote:
table to reference OBJECTS (OBJECTNAME) some day. How would you know
wich of the two records with the same primary key that was referenced?
It's part of the definition of primary key - it must be unique.
You can add a PRIMID INTEGER NOT NULL and put the primary key on that
field instead. Use an index on OBJECTNAME if it speeds things up. In
that case you won't be able to reference it in the future. Do you
actually need OBJECTNAME to be the primary key?
check that you really have a foreign key on OBJECT.ID?
restore to a *new* database or you could loose it all. But I'm not 100%
on that.
> I'm using Firebird 1.5 and have a table desclared as follows:Absolutely not. Think about what would happen if you wanted another
> CREATE TABLE OBJECTS (
> OBJECTNAME VARCHAR (30) CHARACTER SET ISO8859_1 NOT NULL COLLATE
> ISO8859_1,
> ID INTEGER NOT NULL,
> OBJECTNUMBER INTEGER NOT NULL,
> ENABLED INTEGER NOT NULL);
>
>
>
> /* Primary keys definition */
>
> ALTER TABLE OBJECTS ADD PRIMARY KEY (OBJECTNAME);
>
>
> /* Foreign keys definition */
>
> ALTER TABLE OBJECTS ADD FOREIGN KEY (ID) REFERENCES OBJECTGROUPS
> (GROUPID) ON UPDATE CASCADE;
>
> My problem:
> It is possible to add more than one record with the same OBJECTNAME
table to reference OBJECTS (OBJECTNAME) some day. How would you know
wich of the two records with the same primary key that was referenced?
It's part of the definition of primary key - it must be unique.
You can add a PRIMID INTEGER NOT NULL and put the primary key on that
field instead. Use an index on OBJECTNAME if it speeds things up. In
that case you won't be able to reference it in the future. Do you
actually need OBJECTNAME to be the primary key?
> and futhermore changing GROUPID in table OBJECTGROUPS doesn't changeIt should. Did your DDL statements committ without an exception. Can you
> ID in table OBJECTS.
check that you really have a foreign key on OBJECT.ID?
> What is wrong? Is the database corrupted and if so what could I do toIf you can make a backup and restore it should be fine. Be careful to
> fix this?
restore to a *new* database or you could loose it all. But I'm not 100%
on that.
>
> Thankful for any help
>
> Regards Staffan
>
>
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
>