10: Fundamentals of Databases Flashcards
Relational Database
A database where data is held in multiple tables, which are linked together by relationships
Primary Key
An attribute in a database table, that acts as a unique identifier for each record
Composite Primary Key
A primary key that consists of multiple attributes
Attribute
A category heading for each item of data in a column of a table
Foreign Key
A primary key of one table, that appears in another table to create a relationship between them
First Normal Form (3)
- Each record has a primary key
- Data is atomic
- No repeating group of attributes
Second Normal Form
No partial dependencies (where a non-key attribute varies with only part of a composite primary key, a new table must be created)
Third Normal Form
No non-key dependencies (where one non-key attribute varies with another, a new table must be created)
Benefits of Normalised Databases (3)
- Reduction in the amount of duplicated data
- Improved data and referential integrity
- Elimination of insertion, update and deletion anomalies
SQL Retrieve Command
SELECT column_1, column_2, …
FROM table
WHERE condition[s]
ORDER BY column [DESC]
LIMIT num_limit
OFFSET num_offset
SQL Update Command
UPDATE table
SET column_1 = new_value_1, column_2, = new_value_2, …
WHERE condition[s]
SQL Insert Command
INSERT INTO table [(column_1, column_2, …)]
VALUES (value_1, value_2, …)
SQL Delete Command
DELETE FROM table
WHERE condition[s]
SQL Create Table Command
CREATE TABLE table (
column_1 datatype_1 [PRIMARY KEY],
column_2 datatype_2,
…
[FOREIGN KEY (foreign_key_1) REFERENCES other_table (primary_key),
…]
)
A Client Server Database System Provides ____
Simultaneous access to the database for multiple clients
Concurrent Access Can Result In ____ If Two Clients ____
The problem of updates being lost, edit a record at the same time
Record Locks (4)
- A record is locked whenever a user retrieves it for updating
- Another user trying to retrieve the same record is denied access until the transaction is complete
- If two users are trying to update two records, deadlock can occur
- Deadlock is where user 1 locks record 1 and tries to update record 2 in the same transaction, but user 2 has locked record 2 and is trying to update record 1 so neither user can proceed
Serialisation (3)
- Serialisation ensures transactions do not overlap in time so cannot interfere
- A transaction cannot start until the previous one has finished
- Serialisation can be implemented using timestamp or commitment ordering
Timestamp Ordering (5)
- Whenever a transaction starts, it is given a timestamp
- If two transactions affect the same object, the transaction with the earlier timestamp is applied first
- To ensure transactions are not lost, every object has read and write timestamps, which are updated whenever it is read or written to
- When a transaction starts, it reads data, setting a read timestamp
- Before it writes back, if the read timestamp is different, it knows another transaction is taking place, avoiding problems
Commitment Ordering (2)
- Transactions are ordered in terms of their dependencies on each other
- Where one request would cause a deadlock, it is blocked until another is completed