Databases
Table
Databases are made up of tables. A table has columns called fields and rows called records. In IGCSE, databases only consist of a single table.
- Fields are the different categories in a table which organise data belonging to the same group
- Records are groups of data that often have a unique identifier
- Validation is used to set rules for fields
Data Types
Similar to programming, databases also have data types to enforce consistency and prevent errors. Different information can require different data types. It is important to be efficient and account for all possibilities when selecting a data type for a field.
Type | Example |
---|---|
Text & Alphanumeric | Names, Phone Numbers |
Character | Gender |
Boolean | True & False |
Integer | Population |
Real | Money |
Date & Time | Date of Birth |
Phone numbers are always a text field and not a numeric field!
Primary Key
A primary key is a field in a table that acts as a unique identifier for a record. For example, a number plate can be used to uniquely identify a car. Primary keys often have a specific format and are mostly named along the lines of ID
.
SQL
SQL stands for Structured Query Language. It is used to fetch information from a database. Just like most programming languages, SQL has keywords. In IGCSE, only 6 keywords are used.
SELECT
: chooses which fields to display (*
means all fields)FROM
: points to the name of the table where the data can be foundWHERE
: filters records using conditionsORDER BY
: sorts records in ascending order by defaultSUM
: calculates the total a fieldCOUNT
: counts the number of records
SELECT field_1, field_2 FROM my_table WHERE field_1 > 0 AND field_2 = "YES";