Welcome Guest, Not a member yet? Register   Sign In
Help with Foreign Keys
#1

[eluser]orokusaki[/eluser]
Hi,

I'm wondering if somebody out there could explain a foreign key set up and usage for me. I don't necessarily need code, but just a logical explanation. Here's what I know:

Foreign keys are used to identify primary keys in other tables

You can only use a foreign key in an InnoDB table (at least in MySQL)


Here's what I really don't understand:

When I first learned about database interaction a year ago, I read about foreign keys. It made sense to me then because they explained it as such that it was not an actual difference from any other column, but rather it was just a normal column that you knew was a "foreign key", so that you could say

SELECT 'column' FROM 'table' WHERE table.column = other_table.column

Pardon my FUBAR syntax above.

I'm just so confused. I don't know if I should use foreign keys or not. If I have a table called posts and another called comments should I use foreign keys to relate them to each other, or should I just use the foreign key-like logic in my programming?


Messages In This Thread
Help with Foreign Keys - by El Forum - 10-28-2008, 12:39 AM
Help with Foreign Keys - by El Forum - 10-28-2008, 03:11 AM
Help with Foreign Keys - by El Forum - 10-28-2008, 05:07 AM
Help with Foreign Keys - by El Forum - 10-28-2008, 05:11 AM
Help with Foreign Keys - by El Forum - 10-28-2008, 05:16 AM
Help with Foreign Keys - by El Forum - 10-28-2008, 05:18 AM
Help with Foreign Keys - by El Forum - 10-28-2008, 09:06 AM
Help with Foreign Keys - by El Forum - 10-28-2008, 10:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB