Showing posts with label foreign key. Show all posts
Showing posts with label foreign key. Show all posts

Thursday, 28 March 2013

Relational databases: some simple rules (part 2)

   


This is the second part of the two parts article "Relational databases: some simple rules".

In the first part we have seen the ideas of tables and the way we can relate them.
And now... the conclusion!

Primary and foreign keys
We now need to move on a bit, but please keep in mind the example made in the first part of the article: two tables, with a relation for the state column.
The names table has the following columns: ID, name, surname, address, post code, city, state.
The states table has the following columns: ID, state.
In the persons table, the “state” column will contain only IDs related to the states table.
The ID column in the person table is a primary key. The ID in the state table is a primary key.
The “state” column in the persons table is a foreign key.
Quite easy, isn’t it?