Chapter-9Database
Chapter-9Database
IGCSE - CS - 0478
Single-table database
Define Database:
BETWEEN 0 AND 1 Enter a value with a percent sign. (For use with a
field that stores number values as percentages).
<#01/01/2007# Enter a date before 2007.
LIKE "[A-Z]*@[A-Z].com" OR "[A-Z]*@[A-Z].net" Enter a valid .com, .net, or .org e-mail address.
OR "[A-Z]*@[A-Z].org"
[RequiredDate]<=[OrderDate]+30 Enter a required date that occurs no more than 30
days after the order date.
Primary keys
Each record within a table contains data about a single
item, person or event.
entity/entry
Activity 9.3 ( in Lab)
Using Access (or any other suitable database management
software), add the HospitalNumber field to the single table
database PATIENT.
» Choose ‘text’ as the data type for this field.
» Include validation checks to ensure that 8 characters
must be entered starting with HN followed by 6 digits for
example HN123456.
» Choose suitable data to store in each primary key field
for the 6 patients in the table.
Activity 9.4
database record data type char
fields table validation Boolean
records primary key Text field
Select all the fields from the table student where the field “House” is equal to data “Red”
All students with Hobby music
ID FirstName LastName Age House Hobby
Select all the fields from the table student where the field “hobby” is equal to data “music”
SQL- Structured Query Language
Structured Query Language (SQL) is the standard query language
for writing scripts to obtain useful information from a database.
SQL Query Statement Description
SELECT Fetches specified fields (columns) from a table; queries always
begin with SELECT.
WHERE Includes only records (rows) in a query that match a given
condition.
FROM Identifies the TABLE to use
ORDER BY Sorts the results from a query by a given column either
alphabetically or numerically.
SUM Returns the sum of all the values in a field (column). Used with
SELECT.
COUNT Counts the number of records (rows) where the field (column)
matches a specified condition. Used with SELECT.
All students with Hobby music FROM TABLE - STUDENT
SELECT FirstName, LastName,
ID FirstNa LastNam Age House Hobby Hobby
me e
FROM STUDENT
001 Jay Chou 11 Yellow Drawing WHERE Hobby = “Music”;
002 Jane Watson 10 Red Dancing
ID FirstName LastName Hobby
003 Will Smith 13 Blue Music
002 Jane Watson 10 Red Dancing ID First Last Age House Hobby
Name Name
003 Will Smith 13 Blue Music
005 Anna Maria 11 Yellow Music
004 MAX Verst 12 Green Drawing
004 MAX Verst 12 Green Drawing
005 Anna Maria 11 Yellow Music
002 Jane Watson 10 Red Dancing
006 Jay Chou 14 Red Music
001 Jay Chou 11 Yellow Drawing
002 Jane Watson 10 Red Dancing ID First Last Age House Hobby
Name Name
003 Will Smith 13 Blue Music
003 Will Smith 13 Blue Music
004 MAX Verst 12 Green Drawing
004 MAX Verst 12 Green Drawing
005 Anna Maria 11 Yellow Music
001 Jay Chou 11 Yellow Drawing
006 Jay Chou 14 Red Music 006 Jay Chou 14 Red Music
SELECT COUNT(Salesman_ID)
Output: 4
FROM SALESMAN
WHERE Commission >= 0.13
Salesman database
Salesman
_ID
Name City Commission Amount SELECT SUM(Amount)
FROM SALESMAN
5001 James Hoog New York 0.15 5000 WHERE City =”New York”
c Write an SQL query to list all the patients who arrived on 12/11/2022.
d Write an SQL query to list all the patients who arrived between 12/10/2022 AND
30/10/2022.
Six ShorText
Write an SQL query to pick out any cubs in the red six or the blue six.
Write an SQL query to count the number of cubs in the red six.