1.3.2 Databases Flashcards
Flatfile database
- consists of only a single file [1]
- requires little expertise to maintain [1]
- may have redundant data which can lead to increased storage requirements [1]
- flat file database is harder to update so data might be inconsistent [1]
Relational database
- a relational database is one that uses different tables for different entities
- consists of linked tables [1]
- maintains data integrity [1]
Entity
an item of interest about which information is stored
Primary key
- a unique identifier for each record [1]
- used to establish relationships between tables
- can be used to fetch any record from a table
Foreign key
- the field/column which links two tables together [1]
- it is the field/column that refers to the primary key in another table [1]
Secondary key
- specifying another attribute to be indexed for faster search [1]
- an indexed field that is not unique
- the index consumes additional storage space in the database [1]
Entity- relationships modelling
- one -to one
- one - to many
- many to many
One - to - one
Each entity can only be linked to one other entity
One- to- many
One table can be associated with many other tables
Many-to-many
Many tables can be associated with many other tables
Normalisation
- the process of coming up with the best possible layout for a relational database
- normalisation tries to accomplish the following :
- no redundancy so data integrity is maintained
- consistent data throughout linked tables
- records can be added and removed without issues
- complex queries can be carried out
First normal form 1NF
(To get to 1NF a tables must follow 5 rules)
- all field names must be unique ( to avoid confusion about which record should be retrieved or updated)
- values in fields must be from the same domain (e.g data type)
- values in fields should be atomic so for every cell there must only be a single value
- no two records can be identical
- each table needs a primary key
No duplicate records in 1NF
this is because duplicate records take up unnecessary space and can cause inconsistencies if updates are not performed on all of them
Second normal form (2NF)
- the data is already in 1NF
- any partial dependencies have been removed
- meaning no fields can depend on only part of a composite primary key
- so each table should serve its own single purpose
Partial dependency
- Means one of more fields depend on only part of the primary key
- this issue can arise if the primary key is a composite key
Fixing a many to-many relationship
- create a linking table
- assign primary key from the 2 initial tables as the composite primary key for the new linking table
- this flips the M:M relationship to become to 1:M relationships
Third normal form (3NF)
- data is already in 2NF
- any non-key dependencies are removed
- all keys are dependant on the primary key, the whole primary key and nothing but the primary key
Non key dependencies
When the value of a field depends on the value of another field which is not the primary key