GCSE / Computer

Relational Databases and SQL

Learn the fundamentals of relational databases, including tables, records, fields, data types, primary keys, foreign keys and relationships. Understand how SQL is used to retrieve, sort, insert, update and delete data using commands such as SELECT, FROM, WHERE, ORDER BY, INSERT INTO, UPDATE and DELETE.

A database is an organised collection of related data stored electronically so that information can be searched, accessed, managed and updated efficiently. Databases are useful when large amounts of structured information need to be stored and processed.
A relational database stores data in separate but related tables. Each table usually represents one type of entity, and relationships between tables allow information to be connected without repeatedly storing the same data.
A table is made up of rows and columns. Each row normally represents one record, while each column represents a field containing one particular type of information.
A record is a complete set of data about one item or entity in a table. For example, one student record might contain a student ID, name, date of birth and class.
A field is one individual category of data within a table. Examples include surname, date of birth, price or student number. Fields are usually represented as columns in a relational database table.
A data type specifies the kind of data that can be stored in a field. Using appropriate data types helps ensure that values are stored consistently and can be processed correctly by the database.
A primary key is a field that uniquely identifies each record in a table. Every record must be distinguishable from the others, so primary key values must be unique.
A foreign key is a field in one table that refers to the primary key of another table. Foreign keys are used to create relationships between tables in a relational database.
Relational databases reduce data redundancy by avoiding unnecessary duplication of the same information across several tables. Instead, related data can be linked using keys.
Reducing data redundancy also helps reduce data inconsistency. If the same information is stored many times, one copy may be updated while another remains unchanged, causing conflicting data.
SQL stands for Structured Query Language. It is used to interact with relational databases and can be used to retrieve, insert, update and delete data.
The SELECT command is used to choose which field or fields should be displayed in query results. The FROM command identifies the table from which the data should be retrieved.
The WHERE command is used to apply a condition to a query so that only records meeting specified criteria are selected, updated or deleted.
ORDER BY is used to sort SQL query results. ASC sorts values into ascending order, while DESC sorts them into descending order.
INSERT INTO and VALUES are used to add new records to a table. UPDATE and SET are used to change existing data, while DELETE FROM removes records. WHERE is commonly used with UPDATE and DELETE to make sure only the intended records are affected.
Relational Databases and SQL | GCSE Computer Science | TSL