| Forum Home | ||||
| PC World Chat | ||||
| Thread ID: 79661 | 2007-05-27 23:37:00 | Some questions about info system.Primary keys/Foreign keys | Ninjabear (2948) | PC World Chat |
| Post ID | Timestamp | Content | User | ||
| 553746 | 2007-05-27 23:37:00 | I am having a bit of trouble explaining to myself the difference of primary and foreign keys. I took a look here searchoracle.techtarget.com A primary key is a table column that can be used to uniquely identify every row of the table. Any column that has this property will do -- these columns are called candidate keys. A table can have many candidate keys but only one primary key. The primary key cannot be null. A foreign key is a column, or combination of columns, that contain values that are found in the primary key of some table (including, possibly, itself). A foreign key may be null, and almost always is not unique. The explanation seems a bit hard to understand It says that every column can be identify with a primary key.A foreign key is a combination of columns Does that mean that that the names in the department are primary keys and that the names of projects are the foreign keys because the project name relates to the department? Foreign key is a group which belongs to the main group which is the primary key? |
Ninjabear (2948) | ||
| 553747 | 2007-05-27 23:59:00 | Well, that site doesnt tell u much unless u register and then log in. But I take it u mean this (en.wikipedia.org) And this (en.wikipedia.org) |
Speedy Gonzales (78) | ||
| 553748 | 2007-05-28 01:30:00 | Hmm.. Thanks Foreign key is a reference between two tables but isnt primary key the same thing but it identitifes each column with a key? Does that mean that a foreign key can have a group of column but primary key is reference to 1 column only? |
Ninjabear (2948) | ||
| 553749 | 2007-05-28 01:40:00 | Hmm.. Thanks Foreign key is a reference between two tables but isnt primary key the same thing but it identitifes each column with a key? Does that mean that a foreign key can have a group of column but primary key is reference to 1 column only? Say you have two tables Owner(OwnerID, Name, Address, Phone Number) where OwnerID is the primary key - hence if you know an ownerID, then you can uniquely identify a row in the table. Vehicle(Rego, Make, Model, Colour, OwnerID) where Rego is the primary key - can uniquely identify a vehicle. where OwnerID is a foreign key - i.e. it is a field which contains an entry referring to the primary key of another table, to show the relationship between the two tables. It does not necessarily uniquely identify a row in the Vehicle table. A primary key can be made up of more than one columns (composite key) - i.e you require more than one column to uniquely identify a row. A table can have more than one foreign key - say we add a table called Fine(FineID, Time, Date, Place, Rego, OwnerID) which has both Rego and OwnerID as foreign keys, showing that it is related to those two tables. Hope this helps. |
somebody (208) | ||
| 1 | |||||