4.10 Fundamentals of Databases Flashcards
Primary Keys (definition)
The unique identifier for each row
Simple Primary Keys (definition)
Primary keys that only contain one field to make a unique value
Composite Primary Keys (definition)
Primary key that contains more than one field to make a unique value
Foreign Keys (definition)
A field in one table that is linked to the primary key in another table
A primary key that has come from another table
Entity
Table
Record
Row
Attribute
Field
Entity Definition
TableName (Primary Key, field1, field2)
- underline primary key
Relationships: One to One
x -|——|- y
Relationships: One to Many
x -|——-<- y
Relationships: Many to Many
x -|——<- xy ->——| y
middle box contains foreign keys of other boxes to make primary key
Relationship Diagrams are called …
Entity-Relationship Diagrams (ERDs)
Normalisation Rules help …
(3)
- organise data efficiently
- eliminate redundant data
- ensure only related data stored in table
First Normal Form (4)
- no columns with repeated or similar data
- each data item cannot be broken down any further (atomic)
- each row is unique (it has a primary key)
- each field has a unique name
Second Normal Form (2)
- must already be in 1NF
- non-key attributes must depend on every part of the primary key
Third Normal Form (2)
- must already be in 2NF
- there are no non-key attributes that depend on another non-key attribute
Benefits of Normalisation (4x2)
- Easier to query data
- no repetition of data
- no redundant data
- Less chance of errors
- only one instance of each piece of data (no data duplication)
- changes are cascaded throughout the database (only need to change the data once)
- Queries run faster
- less data to search through
- database is optimised
- Less money on storage
- less data = smaller database size
Problems of Normalisation (5)
- Possibility of larger databases and more tables
- requires more storage
- requires more relationships to be assigned between tables
- queries could run slower
- queries are more complex
- Need to be careful making data atomic
Concurrent Access (3)
- when more than one user has access to a record at the same time
- could lead to overwriting entries/changes
- could lead to losing data
Record Locks (2)
- when a user starts to edit a record, a lock is set on the record
- other users can’t edit/access the record until the lock is released
Timestamp Ordering (3)
- timestamps generated for each transaction
- timestamps indicate the order that transactions occurred in
- timestamps can be generated for edits, queries and reading & writing of data
Serialisation (2)
- rather than locking, requests from other users are placed in a queue
- once the first user has finished using the field, the next command in the queue is executed
Commitment Ordering (3)
- an algorithm is used to work out an optimum order in which to execute commands for the same field
- algorithm takes into account the impact of command on other parts of the database
- algorithm attempts to minimise issues from occurring
Insert: every field
INSERT INTO table VALUES (value1, value2);