Databases revision guide

By Interwoven Maths

Practise Databases View all questions Back to Computer Science

Everything you need to know

A database stores data so it can be found, changed and kept consistent. This topic covers how a relational database is structured and the SQL commands used on it.

What a database is

A database is an organised collection of related data, stored so it can be searched and updated efficiently.

Tables, records and fields

A relational database holds data in linked tables. Each table stores data about one kind of thing, called an entity.

A record is one row, holding all the data about one item. A field is one column, holding one attribute across every record. Each field has a data type.

Storing each fact in one place only means it cannot become inconsistent between copies.

Primary and foreign keys

A primary key is a field whose value is unique for every record, so it identifies one record exactly.

A foreign key is a field holding the primary key of another table. It is what links the tables together, so one customer can be connected to many orders.

Retrieving data with SQL

SELECT names the fields wanted and FROM names the table.

WHERE filters which records are returned, and conditions can be joined with AND and OR. ORDER BY sorts the results, with ASC for lowest to highest and DESC for highest to lowest.

Changing data with SQL

INSERT INTO adds a new record. UPDATE changes fields in existing records. DELETE FROM removes records.

UPDATE and DELETE act on every record unless a WHERE clause limits them.

Validation in a database

Validation rules on a field stop unsuitable data being stored, using range, length, presence and format checks.

Back to Databases practice ยท View all Databases questions