Bluehost.com Web Hosting $6.95

Problem with foreign key referencing key on same table?

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 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-29-2007
Phil Latio
 
Posts: n/a
Default Problem with foreign key referencing key on same table?

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


Reply With Quote
  #2 (permalink)  
Old 01-29-2007
strawberry
 
Posts: n/a
Default Re: Problem with foreign key referencing key on same table?



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

Reply With Quote
  #3 (permalink)  
Old 01-29-2007
Phil Latio
 
Posts: n/a
Default Re: Problem with foreign key referencing key on same table?

>>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



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:12 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0