Paper 2: Databases | O Level Computer Science 2210 & IGCSE Computer Science 0478 | Detailed Free Notes To Score An A Star (A*)
- Database
- Collection of data
- It has different tables
- Each table has many different fields
- Each field is a column with specific types of data
- Each field has many different records
- A record is one row in the database
- Data Types
- Text/ Alphanumeric
- Combination of letters, numbers and symbols
- Numbers are treated as text here so they can’t be added or subtracted directly
- Speech marks are used around them
- Character
- A single number or character
- Numbers are still used as text
- Boolean
- Has two options
- Like true false
- No speech marks
- Has two options
- Integer
- A whole number
- Real
- A number with at least one decimal place
- Date/ Time
- A date or/and time
- Text/ Alphanumeric
- Primary Key
- One unique field in the database
- It will not appear twice in any record
- For example, CNIC number can be a primary key in a table that is focused on details of people
- First name and last name in this case are not suitable choice because many people can have the same first name and last name
- SQL
- Structured Query Language
- Important for paper
- It is used to perform actions such as define tables, change tables, add data, search data (main focus of exams) and perform calculations within tables.
- SELECT … FROM
- It allows you to select a field or set of fields form the table
- SELECT field
- FROM table
- For example
- SELECT BookName
- FROM Books
- It will select Book Name column (field) from the Books table
- If more than one selection, we can use a comma between them i.e. SELECT BookName, Genre (two fields selected
- SELECT FROM WHERE
- Including where will allow selection of only specific data
- Here, we can use logical operators
- = equal to
- < less than
- <= less than equal to
- > greater than
- >= greater than equal to
- <> Not equal to
- For example
- SELECT FirstName, LastName, Posted
- FROM Orders
- WHERE Posted = Yes
- Only the first names, last names and posted information from orders table will be selected where posted has a value of yes. Any record with posted value as no won’t be selected.
- More than one condition
- We use BOOLEAN Operators
- AND
- Both conditions must be true
- OR
- Any one condition or both conditions must be true
- AND
- No comma between the conditions just the logical operator
- WHERE Condition 1 BOOLEAN Condition 2
- We use BOOLEAN Operators
- Selecting values in or not in a condition
- It is not necessary to also select the field that we use in the condition
- For example
- SELECT FirstName, LastName
- FROM Orders
- WHERE Posted = Yes
- Although we didn’t select the field of POSTED for display, we can still run a condition on it
- Order by
- We can use this to order the data ascending or descending
- ORDER BY field name and then ASC or DESC
- The order field can be different from the ones we have selected
- SUM
- SELECT Sum (field)
- FROM table
- We can also put a condition with WHERE
- It will provide the added total of the field
- COUNT
- Select COUNT (field)
- FROM table
- Where for condition
