Databases and Normalisation
Last Update Unknown
Databases and Normalisation
Relational Database: A database where the data is structured as a series of tables which are joined together.
Primary Key: An attribute which uniquely identifies a record in a database table.
Composite Key: A collection of attributes which uniquely identifies a record in a database table.
Foreign Key: A field in a table which corresponds to the Primary Key field of a different table.
One-to-one
A blind person owns a guide dog which is exclusively theirs.
One-to-many
A doctor may have many patients, but a patient is assigned to only one doctor.
Many-to-many
A film may have many stars and each star may act in many films.
The Three Major Stages of Normalisation
First Normal Form (1NF)
An entity (table) is in 1NF if it contains no repeating groups of attributes.
Second Normal Form (2NF)
An entity is in 2NF if no non-key attribute is dependent on only part of the primary key.
Third Normal Form (3NF)
An entity is in 3NF if attributes depend on nothing but the key.
What does it mean for a database to be normalised?
Every attribute is dependent on the key, the whole key and nothing but the key.
Why is normalisation important?
Eliminates update, insertion and deletion anomalies.
Normalisation Steps
1NF
1. Remove repeating groups of attributes to create a new entity
2. Copy the primary key to any new tables
2NF
3. Check for partial key dependencies
4. Copy these to a new table with the attribute they depend on as the primary key
3NF
5. Check for non-key dependencies
6. Copy these to a new table with the attribute they depend on as the primary key.
Entity Relationship Diagrams
Within fully normalised databases, many-to-many relationships cannot exist between two tables unless the relationship exists through a linking table.
Database Protection
Record Lock: When a user starts to edit a record a lock is set on that record (not the database) so other users cannot change that record until the lock is released
Serialisation: Serialisation ensures only one transaction at a time is executed
Timestamp Ordering: Timestamps are generated for each transaction, database server rules determine if transaction results in loss of data integrity (if so, abort)
Commitment Ordering: An algorithm is used to create a commit order which avoids conflicts between transactions.