Databases
Advanced database concepts including normalisation and DBMS.
Topics
- Relational Databases
- Normalisation
- Entity-Relationship Diagrams
- Data Definition Language
Lessons
- Lesson 1: Database Concepts & File-Based Storage
- Lesson 2: Relational Databases, Keys & ERDs
- Lesson 3: Normalisation - 1NF, 2NF & 3NF
- Lesson 4: Database Management Systems (DBMS)
Key terms
8.1 Database concepts
- Database
- An organised collection of related data that can be stored, searched and managed.
- Relational database
- A database made of tables that are linked to each other using keys.
- File-based storage
- Keeping data in separate files for each application or department, with no links between them.
- Data inconsistency
- The same data differing between copies because one was updated and another was not.
- Table (relation)
- A set of data about one type of entity, arranged in rows and columns.
- Record (tuple)
- A row in a table holding all the data about one item.
- Field (attribute)
- A column in a table holding one piece of data about each item.
- Entity
- A real-world object or concept that data is stored about, such as a student.
- Primary key
- A field (or fields) that uniquely identifies each record in a table.
- Candidate key
- Any field or combination of fields that could be used as the primary key.
- Secondary key
- A candidate key that is not chosen as the primary key, often used for searching.
- Composite key
- A primary key made of two or more fields taken together.
- Foreign key
- A field in one table that is the primary key of another table, creating a link between them.
- Referential integrity
- Every foreign key value must match an existing primary key value, so there are no broken links.
- One-to-one relationship
- One record in table A relates to exactly one record in table B.
- One-to-many relationship
- One record in table A can relate to many records in table B.
- Many-to-many relationship
- Records in each table can relate to many records in the other. It is resolved with a linking table.
- Cardinality
- The number of records on each side of a relationship: one-to-one, one-to-many or many-to-many.
- Entity-relationship (ER) diagram
- A diagram showing the entities in a database and the relationships between them.
- Data redundancy
- The same data being stored more than once, which wastes space and can cause inconsistency.
8.1.2 Normalisation
- Normalisation
- Organising tables to remove redundancy and avoid anomalies.
- Atomic value
- A single, indivisible value in a field, not a list.
- First normal form (1NF)
- No repeating groups, every field holds an atomic value, and each record can be uniquely identified.
- Second normal form (2NF)
- In 1NF, and every non-key field depends on the whole primary key (no partial dependencies).
- Third normal form (3NF)
- In 2NF, and no non-key field depends on another non-key field (no transitive dependencies).
- Partial dependency
- A non-key field that depends on only part of a composite primary key.
- Transitive dependency
- A non-key field that depends on another non-key field rather than directly on the primary key.
- Insertion anomaly
- Being unable to add new data without also adding unrelated data.
- Deletion anomaly
- Deleting a record accidentally removes other data that should have been kept.
- Modification anomaly
- The same data stored in several places must be changed everywhere, or it becomes inconsistent.
- The key, the whole key and nothing but the key
- A memory aid: 1NF needs a key, 2NF depends on the whole key, 3NF depends on nothing but the key.
8.2 Database management system
- Database management system (DBMS)
- Software that creates, manages and controls access to a database.
- Data dictionary
- A store of metadata describing the database, such as table names, fields, data types and keys.
- Data modelling
- Defining the structure of the data and how it is organised before the database is built.
- Logical schema
- A description of the database's structure, such as its tables and relationships, independent of how it is physically stored.
- Data independence
- Changing how data is stored without having to change the programs that use it.
- Concurrency control
- Managing several users accessing the same data at once so that they do not conflict.
- View
- A virtual table made from a query, showing users only the data they need.
- Backup and recovery
- Regularly copying the database and being able to restore it after loss or corruption.
- Access rights
- Permissions that control which users can see or change which data.
- Database administrator (DBA)
- The person who manages the database, including its security, performance and backups.
- Query processor
- The part of a DBMS that interprets and runs queries.
8.3 SQL: DDL and DML
- Data definition language (DDL)
- The part of SQL used to create and change the structure of a database.
- Data manipulation language (DML)
- The part of SQL used to add, change, delete and retrieve data.
- CREATE TABLE
- Creates a new table, including its fields, data types and keys.
- ALTER TABLE
- Changes the structure of an existing table, for example by adding a field.
- SELECT ... FROM
- Retrieves the chosen fields from a table.
- WHERE
- Filters records so only those meeting a condition are returned or changed.
- ORDER BY
- Sorts the results of a query by one or more fields.
- GROUP BY
- Groups records with the same value so that totals or counts can be found for each group.
- INNER JOIN
- Combines records from two tables where the linked fields match.
- INSERT INTO
- Adds a new record to a table.
- UPDATE ... SET
- Changes the values in existing records.
- DELETE FROM
- Removes records from a table.
- Aggregate functions
- SQL functions such as COUNT, SUM, AVG, MIN and MAX that calculate a single value from many records.
Practice questions for Databases