[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
BeginnersGuideToDatabase

Databases

A database consists of one or more tables, and a table normally represents an entity we wish to store information about, for example, a car. The table has  ?fields (also called attributes) in it, which can be seen to represent the properties of the entity, e.g. registration number, colour, manufacturer, number of doors, etc. Data is stored in records (sometimes known as rows), and each car in the table will have a record with data for each of the fields.

Primary Keys

A table in a database should have a primary key. This is a field that is unique to every record in the database. Continuing the cars example, this would be the registration number (as no two cars should have the same one).

Relational Databases =

In real life different entities are related to each other in various ways. For example, a car has an owner. We will have a table for cars and a table for owners. However, one owner might own many cars (we must presume for a moment that one car has one owner). Therefore, we add a field to the cars table that states the primary key of the owner. This field is called a foreign key.

Types Of Relationship

In the above example, one owner could have many cars; a one to many relationship. This is what we want. However, it is also possible to have one to many relationships (these tend to occur when you have more than one table representing a single entity) and many-to-many relationships (these can crop up quite naturally, and you work around them by making a link table).

Normalisation

Normalising a database involves ensuring several factors are true, such as:-
  • All relationships between tables should be one to many.
  • No repeated fields. For example, you don't make a table to store details of CDs with fields called Track1, Track2, Track3 etc. You instead have to create a tracks table and a CDs table and relate the tracks to the CDs they are on. Of course, if one track can be on many CDs you need a link table.
:) It is good practice to normalise a database.

last edited (May 9, 2005) by webmaster12, Number of views: 5320, Current Rev: 6 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.