This is a discussion on Problem with foreign key referencing key on same table? within the MySQL Database forums, part of the Database Forums category; I'm quite new to actually designing databases and have come across something I've not done before. Basically one ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm quite new to actually designing databases and have come across something
I've not done before. Basically one column in a table references another column in the same table and I'm wondering is the correct? destination_id (PK) destination_parent_id (FK ??? as it must take a value from destination_id) destination_name destination_description However the problem I theorectically have is that when I create the first record, destination_parent_id will be looking up a value in destination_id but there will not yet be any value because it is the first record. So are there any ways rounds this? Could I allow destination_parent_id to accept a null value as get around? Cheers Phil |
|
|||
|
On Jan 29, 1:26 pm, "Phil Latio" <phil.la...@f-in-stupid.co.uk> wrote: > I'm quite new to actually designing databases and have come across something > I've not done before. Basically one column in a table references another > column in the same table and I'm wondering is the correct? > > destination_id (PK) > destination_parent_id (FK ??? as it must take a value from destination_id) > destination_name > destination_description > > However the problem I theorectically have is that when I create the first > record, destination_parent_id will be looking up a value in destination_id > but there will not yet be any value because it is the first record. > > So are there any ways rounds this? Could I allow destination_parent_id to > accept a null value as get around? > > Cheers > > Phil >Could I allow destination_parent_id to accept a null value as get around? Yes |
|
|||
|
>>Could I allow destination_parent_id to accept a null value as get around?
> > Yes After posting this question, I thought how lazy of me and actually tried it and on a test table and was surprised my idea (of getting around this problem) actually worked. Thanks for reconfirming. Cheers Phil |