Could anyone tell me what is the real benefit of using a foreign key?
Let's say I have 2 tables, one with references to categories.
my_categories
id | name
1 | sun
2 | rain
3 | wind
my_info
id | name | cid
1 | Mt. Doom | 2
2 | Dodo Hills | 2
3 | Balaba desert | 3
4 | Tilula plains | 1
I can join two tables using
SELECT A.*, B.name as category FROM my_table A LEFT OUTER JOIN my_ref_table B ON (A.cid = B.id)
resulting in this display
1 | Mt. Doom | rain
2 | Dodo Hills | rain
3 | Balaba desert | wind
4 | Tilula plains | sun
In this case, where does the use of a foreign key would improve a search?
Let's say I have 2 tables, one with references to categories.
my_categories
id | name
1 | sun
2 | rain
3 | wind
my_info
id | name | cid
1 | Mt. Doom | 2
2 | Dodo Hills | 2
3 | Balaba desert | 3
4 | Tilula plains | 1
I can join two tables using
SELECT A.*, B.name as category FROM my_table A LEFT OUTER JOIN my_ref_table B ON (A.cid = B.id)
resulting in this display
1 | Mt. Doom | rain
2 | Dodo Hills | rain
3 | Balaba desert | wind
4 | Tilula plains | sun
In this case, where does the use of a foreign key would improve a search?
Comment