a2 computing database design and the relational model
DESCRIPTION
CPT 5 Course document.TRANSCRIPT
Database Design and the Relational Model
Entity-relationship modelling.Normalisation techniques
Illustrate the principles of database design using these techniques in the production of normalised tables that control redundant data, studied up to BCNF.
Entities and Entity-Relationship Diagramming
An entity is an object, person, place, concept, activity, event or thing of interest to an organisation and about which data is recorded.
An attribute is a property or characteristic of an entity. {In relational databases such as Microsoft’s Access it is given the name field]
A relationship is an association or link between two entities.
An entity-relationship diagram models the relationship between TWO ENTITIES as follows:
NB Entity names should always be singular
The following symbol is used to model the link or association
In this representation we are modelling a one-to-many relationship.
The degree of a relationship can be one of the following:
One-to-One =
Ward Patient
IsOccupiedBy
One-to-Many =
Many-to-Many =
The entity Ward ( WardName, NurseInCharge, NumberOfBeds )
WardName is underlined because it is the identifier for the entity Ward.
An entity identifier is an attribute or combination of attributes which uniquely identify an instance or occurrence of the entity.
Attributes of entity Ward
Ward
WardName NurseInCharge NoOfBeds Nightingale Miss Smith 30 Victoria Mrs Brawn 20 Aylesbury Mr Lilo 35
Patient ( PatientID, Surname, Forename, DOB, Sex, NextOfKin )
PatientId Surname Forename
DOB Sex NextOfKin
1 Biggs Sid 19/2/60 M J. Smith2 Brawn Ann 21/6/59 F R. Brawn3 Cragg Alf 14/7/58 M E. Cragg4 Dodds Sam 25/3/61 M R. Dawn
Relational Database Theory
When a systems analyst has finished capturing the data requirements for a new system, he/she will have recorded the data requirements in
1. Data dictionary
2. A set of entity descriptionse.g. Ward ( WardName, NurseInCharge, NoOfBeds )
3. A set of entity-relationship diagrams
An instance or occurrence of the entity Ward (one row of table)Connection line – means Brawn
is in Nightingale wardWard Patient
IsOccupiedBy
The designer will now choose a design. Let’s suppose he/she has chosen to use a relational database such as
Access or Paradox
or SQL Server or Interbase or Oracle.
A relational database consists of a collection of tables. It models relationships (e.g. one-to-many) using shared or common attributes.
In our example, the entity Patient must be modified when it is turned into a relation (A relation is just a fancy name for a table in relational database theory).
An example of a relation is
Ward ( WardName, NurseInCharge, NoOfBeds )
The entity identifier becomes known as the Primary Key in relational theory.
Entity Patient becomes relation Patient as follows
Patient ( PatientID, Surname, Forename, DOB, Sex, NextOfKin, WardName)
This has come form the Ward entity where it is the entity identifier
This is the Foreign Key – because it is the primary key in another relation
WardName = Common attribute
Golden Rules
1. When a One-to-Many relationship exists between two entities, the equivalent relations are created by incorporating/exporting a copy of the entity identifier on the one-side entity to the entity on the many-side.
2. Before turning entities into relations any Many-to-Many relationships must be replaced by two One-to-Many relationships as follows:
NB A relation is a mathematical concept with a name and a set of attributes. Its physical depiction is a table with named columns. For example,
Student ( StudentIdNo, Surname, Forename, DateOFBirth )
The name of the relation is Student. An example of an attribute is Surname.
In this situation a third entity is invented C. It will have, at least, the entity identifiers from entities A and B.
e.g. C ( EIA, EIB )
A B
C
A B