Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

17-Structured-Query-Language-SQL-SAMPLE-A-Level

Teach Computer Science offers affordable, high-quality resources for teaching computer science to students aged 11 and above, suitable for various educational environments. The document includes an introduction to SQL, example queries, activities, flashcards, and a quiz to reinforce learning. Additionally, it provides details on licensing and encourages educators to support the initiative for accessible education.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

17-Structured-Query-Language-SQL-SAMPLE-A-Level

Teach Computer Science offers affordable, high-quality resources for teaching computer science to students aged 11 and above, suitable for various educational environments. The document includes an introduction to SQL, example queries, activities, flashcards, and a quiz to reinforce learning. Additionally, it provides details on licensing and encourages educators to support the initiative for accessible education.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Teach Computer Science

Free Sample
THANK YOU FOR DOWNLOADING THIS FREE SAMPLE RESOURCE!
Here, you’ll find a snippet of the module, which you can use to gauge the quality
of our offering, but will also find super useful in the classroom.

Teach Computer Science is an affordable, high-quality offering for teachers and


students alike whether that’s in the classroom, online, or homeschool
environment. You’ll find everything you need to learn or teach a computer
science subject for students aged 11-14, 14-16, and 16+ following any of the UK
examination boards, or any other curriculum from around the world.

If you want the complete module, which contains classroom presentation,


revision notes, quizzes, mind maps, flashcards, activities and answer keys, then
please upgrade to one of our Premium plans and support our quest to make
education affordable for all.

The Teach Computer Science Team

teachcomputerscience.com
Teach Computer Science
A-Level

Structured Query
Language (SQL)

teachcomputerscience.com
1.

Revision notes

teachcomputerscience.com
Introduction
SQL is a declarative programming language used to access and
manage databases. The SQL statements use simple language and are
easy to understand and remember.
Let us work with a database that is responsible for maintaining the
details of students, teachers, courses and prints grades of students.
The entity relationship diagram along with the entity descriptions is
given. We will use this database as an example for learning queries.

Student CourseGrade Course

Teacher

Student (StudentID, StudentName, Major, DateOfBirth)


CourseGrade (CourseID, StudentID, Grades)
Course (CourseID, CourseTitle, TeacherID)
Teacher (TeacherID, TeacherName, DateOfJoining)
The part of table ‘Student’ is given.

StudentI
StudentName Major DateOfBirth
D
S291 David Watson Science 21/03/1998
S157 Helen Williams Economics 30/04/1999
S918 Paul Ingram Architecture 14/05/1998
S241 Rosemarie Collin Science 19/07/1999
S511 John Rayner Business 12/11/1998
S256 Alan Cross Economics 12/08/1999
S791 Samuel Smith Architecture 19/10/1999

teachcomputerscience.com
The syntax for a SELECT query in SQL is:
SELECT field_names FROM table_name WHERE condition ORDER BY
field_name
A * symbol is used for field_names if all columns are to be displayed.
The query to print the complete table is:
SELECT * FROM Student
The query to print StudentName and StudentID of students born in
the year 1998 in alphabetical order is:
SELECT StudentID, StudentName FROM Student WHERE DateOfBirth
BETWEEN #01/01/1998# AND #31/12/1998# ORDER BY StudentName
The ORDER BY clause by default orders in ascending order. The result
for this query is:

StudentI
StudentName
D
S291 David Watson
S511 John Rayner
S918 Paul Ingram

teachcomputerscience.com
2.

Activities

teachcomputerscience.com
Activity-1
Duration: 20 minutes

1. A table Product maintains the details of products such as product


identity number (primary key), product title, selling price, quantity
available and date in which the product was launched.

SellingPric Quantit
PrdID PrdTitle LaunchDate
e (£) y

110 Fire 7 tablet 50 100 21/03/2019

Samsung Galaxy Tab 149 200 30/04/2018


111
A
112 Fire HD 8 tablet 80 250 14/05/2017

113 Fire HD 10 tablet 150 150 19/07/2019

114 Apple iPad 295 50 12/11/2019

Fire HD 8 Kids 130 90 12/08/2017


115
edition
116 Huawei MediaPad T3 120 180 19/10/2016

Write SQL queries for the following:


A. What is the query to create this table?

A. What query was used to enter the record with PrdID=113 into this
table?

teachcomputerscience.com
Activity-1
Duration: 20 minutes

1. A table Product maintains the details of products such as product


identity number (primary key), product title, selling price, quantity
available and date in which the product was launched.

SellingPric Quantit
PrdID PrdTitle LaunchDate
e (£) y

110 Fire 7 tablet 50 100 21/03/2019

Samsung Galaxy Tab 149 200 30/04/2018


111
A
112 Fire HD 8 tablet 80 250 14/05/2017

113 Fire HD 10 tablet 150 150 19/07/2019

114 Apple iPad 295 50 12/11/2019

Fire HD 8 Kids 130 90 12/08/2017


115
edition
116 Huawei MediaPad T3 120 180 19/10/2016

Write SQL queries for the following:


A. What is the query to create this table?

CREATE TABLE Product (PrdID INTEGER PRIMARY KEY,


PrdTitle varchar(20), SellingPrice Currency , Quantity
INTEGER, LaunchDate DATE)

A. What query was used to enter the record with PrdID=113 into this
table?

INSERT INTO Product (PrdID, PrdTitle, SellingPrice,


Quantity, LaunchDate) VALUES (“113”, “Fire HD 10 tablet”,
150, “150”, #19/07/2019#);

teachcomputerscience.com
Flashcards

What operator
represents not equal to != or <>
in SQL?

What operator is used


in SQL to filter records BETWEEN … AND …
within the limit
specified?

teachcomputerscience.com
Glossary
A data type used in programming language
Boolean
to represent two values: TRUE or FALSE.

An organised collection of data which allows


Database users to obtain and process information
according to their requirements.

A column of a table that is a link to a primary


Foreign key
key of another table.

INT Data type in SQL to represent integers

A symbol that tells the compiler to perform


Operators
specific mathematical and logical operations.

A column of a table that uniquely identifies


Primary key
each record.

teachcomputerscience.com
Quiz
1. What is the function of != operator?
A. Less than
B. Greater than
C. Equal to
D. Not equal to

2. Which of the following statement is used to display all the fields


of a table?
A. SELECT * FROM table_name
B. CREATE * FROM table_name
C. DISPLAY * FROM table_name
D. None of the above

3. Which of the following are Boolean operators?


A. AND, OR and NOT
B. ADD, SUB, MULT and DIV
C. ORDER BY and WHERE
D. None of the above

4. Which of the following clauses is used to select records while


displaying results using a SELECT statement?
A. UPDATE
B. ORDER BY
C. WHERE
D. WHICH

teachcomputerscience.com
Teach Computer Science

This resource is licensed under the Creative Commons Attribution-


NonCommercial 4.0 International license.

You are free to:

● Share — copy and redistribute the material in any medium or


format
● Adapt — remix, transform, and build upon the material

Under the following terms:

● Attribution — You must give appropriate credit, provide a link to


the license, and indicate if changes were made. You may do so
in any reasonable manner, but not in any way that suggests the
licensor endorses you or your use.
● NonCommercial — You may not use the material for
commercial purposes.

For more information on this license, visit the following link:

http://creativecommons.org/licenses/by-nc/4.0/

Thank you!

teachcomputerscience.com
Teach Computer Science

Thank you so much for downloading this resource!

We hope it has been useful for you in the classroom and that your
students enjoy the activities.

For more teaching resources like this, don’t forget to come back
and download the new material we add every week!

Thanks for supporting Teach Computer Science. We can provide


teachers with low-cost, high-quality teaching resources because
of our loyal subscribers and hope to serve you for many years to
come.

- The Teach Computer Science Team :)

teachcomputerscience.com

You might also like