Download presentation
Presentation is loading. Please wait.
Published byCalvin Freeman Modified over 6 years ago
1
GCSE COMPUTER SCIENCE Data 2.4 Databases & SQL
2
Are used to store structured data.
Structured & Unstructured Data You need to be able to name some examples of structured and unstructured data. Unstructured Data Photos Presentations Videos Documents Structured Data Phone Book Address Book Customer Details Train Timetable Databases Are used to store structured data.
3
Key Terms Field One piece of information. Record
All of the data or information about one item. Primary Key A unique identity for each record. Table Stores all of the information about one particular category. Student_ID First_Name Last_Name Address DOB Gender 1 Peter James 310 Brook Lane 21/05/1985 Male 2 Tony Jackson 7 Somerset Avenue 15/12/1992 3 Sarah Jones 35 West End Road 6/08/1980 Female ACTIVITY Write the three key definitions in your exercise book.
4
Activity 1 Can you find an example in this database showing a primary key, field, record and table? Primary Key ID Name Breed Gender Date_Of_Birth Enclosure Capacity Headkeeper C009 Toni Tiger Male 30/6/1982 Big Cats 12 J Milner C015 Andrew Lion Female 18/6/2009 A007 Chimpy Chimpanzee 19/7/2011 Ape House 50 S Larkin Record Table Field
5
Turn the A4 sheet into a revision poster by:
Activity 2 Instructions Cut out the table and stick it in the middle of a page in your book. Write in the elements and group them to form records for each video game. Turn the A4 sheet into a revision poster by: Adding ‘Databases’ as the title Labelling the primary key and writing a short definition of the term. Labelling a field and writing a short definition of the term. Labelling a record and writing a short definition of the term. Labelling the table and writing a short definition of the term.
6
Correct Groups Game ID Title Platform Genre Release Date 01 Pacman
Arcade 1980 02 Halo Xbox First Person Shooter 2001 03 Minecraft PC Survival 2009 04 Wii Sports Wii Sports 2006 05 Super Mario Bros. NES 1985
7
Write this in formation about relational databases in your book.
Relational Databases split data across different tables to reduce duplication. A foreign key is used to link tables together and create a relationship between them. Student_ID First_Name Last_Name Address DOB Gender Class_ID Student_ID Subject Teacher_ID A foreign key is a field in one table that is linked to a primary key in another table. ACTIVITY Write this in formation about relational databases in your book.
8
Activity 3 How could this table be split into two linked tables called Animal and Enclosure? Write down the field names that should go in each table. ID Name Breed Gender Date_Of_Birth Enclosure Capacity Headkeeper C009 Terry Lion Male 30/6/1982 Big Cats 12 J Milner A019 Sam Gibbon Female 10/6/2002 Ape House 50 S Larkin C015 Toni Tiger 18/6/2009 B033 Bob Red deer 6/7/2007 Deer Park 200 A Hunt A007 Charlie Chimpanzee 19/7/2011 ANSWER ANIMAL Table: ID, Name Breed, Gender Date_of_Birth, Enclosure. ENCLOSURE Table: Enclosure, Capacity, Headkeeper.
9
Activity 4 Re-organise the data from the Zoo table in Activity 2 in to two linked tables called Animal and Enclosure.
10
Activity 4 Answer ID Name Breed Gender Date_of_Birth Enclosure C009
Terry Lion Male 30/6/1982 Big Cats A019 Sam Gibbon Female 10/6/2002 Ape House C015 Toni Tiger 18/6/2009 B033 Bob Red Deer 6/7/2007 Deer Park A007 Charlie Chimpanzee 19/7/2011 Enclosure Capacity Headkeeper Big Cats 12 J Milner Deer Park 50 S Larkin Ape House 200 A Hunt
11
SQL = < > <= >= <>
Structured Query Language is the language used to search databases. You need to be able to read and write simple SQL statements. The following comparison operators are used in SQL statements: Comparison operator Symbol Equal to = Less than < Greater than > Less than or equal to <= Greater than or equal to >= Not equal to <> Apart from equal to and not equal to they are the same as Python.
12
Here is an example SQL statement
SQL Statements Here is an example SQL statement SELECT First_Name from Student WHERE Gender=“Male” Fields to show The table Search criteria This statement selects the First_Name from the Student table and only shows the Male students. Student_ID First_Name Last_Name Address DOB Gender 1 John Curtis 12 Brook Lane 21/03/1990 Male 2 Ben Jackson 1 Totters Lane 15/04/1990 3 Sarah Smith 60 Belsize Rd 6/06/1990 Female First_Name John Ben
13
SQL Commands Command Description Deletes rows from a database table.
DELETE FROM TableName WHERE condtion Deletes rows from a database table. CREATE TABLE TableName (FieldName data type, …) Creates a database table. INSERT INTO TableName VALUES (Value, …) Inserts row into a database table. SELECT (FieldName, …) FROM TableName WHERE condition ORDER BY (FieldName, ..) Retrieves data from a table. The asterisk (*) can be used if all columns are required in the output. FROM Table1Name, Table2Name, … WHERE join criteria Retrieves data from two related tables. UPDATE TableName SET (FieldName=Value, …) Updates rows in a database table.
14
Included in search results Not included in search results
SQL Practical: Instructions Several volunteers are needed! Each of you is a record in a database called Students. For each query displayed you will go to one side of the room. Go to the left if your record would be included in the query results and to the right if your record wouldn’t be included in the query results. Included in search results Not included in search results
15
Included in search results Not included in search results
SQL Practical Included in search results QUERY 1 Not included in search results SELECT * FROM Students
16
SQL Practical SELECT * FROM Students WHERE HairColour = “Blond”
Included in search results QUERY 2 Not included in search results SELECT * FROM Students WHERE HairColour = “Blond”
17
SQL Practical SELECT * FROM Students WHERE EyeColour = “Blue”
Included in search results QUERY 3 Not included in search results SELECT * FROM Students WHERE EyeColour = “Blue”
18
SQL Practical SELECT * FROM Students WHERE EyeColour = “Brown”
Included in search results QUERY 4 Not included in search results SELECT * FROM Students WHERE EyeColour = “Brown” ORDER BY FirstName
19
Included in search results Not included in search results
SQL Practical Included in search results QUERY 5 Not included in search results SELECT * FROM Students WHERE BirthMonth > 7 ORDER BY Height
20
SQL Practical SELECT * FROM Students WHERE BirthMonth <= 5
Included in search results QUERY 6 Not included in search results SELECT * FROM Students WHERE BirthMonth <= 5 ORDER BY FirstName DESC
21
SQL Practical SELECT * FROM Students
Included in search results QUERY 7 Not included in search results SELECT * FROM Students WHERE HairColour = “Brown” or HairColour = “Black” ORDER BY FirstName DESC
22
SQL Practical SELECT * FROM Students
Included in search results QUERY 8 Not included in search results SELECT * FROM Students WHERE HairColour = “Black” and EyeColour = “Brown” ORDER BY LastName DESC
23
Link: https://www.codeschool.com/courses/try-sql
Activity 5 Sign up for a free Code School account and complete the Try SQL course. Link:
24
Use this table to help you answer the following activities.
Marksheet Table TABLE 1 Use this table to help you answer the following activities. Name Assign1 Assign2 Assign3 Average Aisha 51 60 64 58 Katharine 75 76 48 70 Fiona 100 87 72 86 Gareth 65 69 73 Jo 38 52 44 45 Manjit 66 68 Ian 13 17 26 19 Michael 43 33 40 Ubaid 55 50 53 Simon Mark 25 15 Gemma 78
25
Activity 6 Question Answer v v v v USE TABLE 1
SELECT Name FROM Marksheet WHERE Assign1=0 Mark SELECT Name FROM Marksheet WHERE Assign1>80 Fiona Gareth SELECT Name , Average FROM Marksheet WHERE Assign1<=30 Ian, 19 Mark, 13 Display the Name and Average of all the students that scored 60 or above in Assign3. SELECT Name, Average FROM Marksheet WHERE Assign3 >= 60 Display the Name and Average of all the students that scored less than 40 Assign2. SELECT Name, Average FROM Marksheet WHERE Assign2 < 40 Display the Name and Average of all the students that did not score 40 in Assign1. SELECT Name, Average FROM Marksheet WHERE Assign1 <> 40 v v v v USE TABLE 1
26
Use this table to help you answer the following activities.
Food_Item Table TABLE 2 Use this table to help you answer the following activities. Product_Code Product_Name Price Supplier_Code Quantity_In_Stock 1239T Baked beans 0.34 S121/A 154 1237T Tomato soup 0.56 450 1309T Spaghetti hoops 0.80 99 4550F Oven chips 1.24 S234/F 550 3444F Fish fingers 1.45 756 2121G Frankfurters 1.02 S009/C 52 5544C Sausage rolls 2.45 S100/C 150
27
Search (also called a Query)
Activity 7 Task Search (also called a Query) Write the SQL command to insert a new record into Products table, for a product with these details: Product_Code: 5500C Product_Name: Pork pie Price: 2.45 Supplier_Code: S100/C Stock: 150 INSERT INTO Products VALUES (5500C, Pork pie, 2.45, S100/C, 150) Write the SQL command to update the record for Tomato soup, the Quantity_In_Stock is now 415. UPDATE Products SET (Quantity_In_Stock = 415) Write the SQL command to delete the Oven chips record from the Food_Item Table. DELETE FROM Products WHERE (Product_name = Oven chips) Write the SQL command to delete one more record of your choice from the Food_Item Table. v v v USE TABLE 2
28
puzzle maker criss-cross
Activity 8 Crossword Create a crossword based on this topic using the online crossword generator linked below. It should have a minimum of 10 questions. When you have finished, paste your crossword on to a Powerpoint slide and name it Databases & SQL. Print out one copy (include your name) and stick it in your book. puzzle maker criss-cross
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.