📚 IGCSE CIE Computer Science: SQL Exam Guide | IGCSE CIE 计算机:SQL 考点精讲
Structured Query Language (SQL) is the standard language for managing and manipulating relational databases. In the IGCSE CIE Computer Science syllabus, you are expected to understand and write basic SQL statements to interact with a single-table database. This guide breaks down every essential SQL command you need for the exam, complete with examples and tips to help you avoid common mistakes.
结构化查询语言(SQL)是管理和操作关系数据库的标准语言。在 IGCSE CIE 计算机科学大纲中,你需要理解并编写基本的 SQL 语句来与单表数据库进行交互。本指南将拆解考试所需的每个核心 SQL 命令,并提供示例和技巧,帮助你避开常见错误。
1. Database Basics and Role of SQL | 数据库基础与SQL的作用
A relational database stores data in tables made up of rows (records) and columns (fields). SQL allows us to query, insert, update, and delete data efficiently without knowing how the data is physically stored.
关系数据库将数据存储在由行(记录)和列(字段)组成的表中。SQL 使我们能够高效地查询、插入、更新和删除数据,而无需了解数据的物理存储方式。
2. The SELECT and FROM Statements | SELECT和FROM语句
The most basic SQL query uses SELECT and FROM to retrieve data. To get all columns from a table, use an asterisk wildcard: SELECT * FROM Students;. This returns every record and every field from the Students table.
最基本的 SQL 查询使用 SELECT 和 FROM 来检索数据。要获取表中的所有列,请使用星号通配符:SELECT * FROM Students;。这将返回 Students 表中的所有记录和所有字段。
The keyword SELECT specifies which columns to display, and FROM specifies which table to read from. In an exam, always check the table name and field names given in the question.
关键字 SELECT 指定要显示哪些列,FROM 指定要读取哪个表。在考试中,一定要根据题目给出的表名和字段名进行核对。
3. Selecting Specific Columns | 选择特定列
Instead of retrieving every column, you can list only the fields you need, separated by commas: SELECT Name, Age FROM Students;. This reduces the amount of data returned and is more precise.
你可以只列出需要的字段(用逗号分隔),而不是检索每一列:SELECT Name, Age FROM Students;。这样可以减少返回的数据量,并且更加精确。
Remember to use commas between column names, but avoid trailing commas. In the exam, the column names must match exactly the field names provided in the table schema.
请记住在列名之间使用逗号,但不要使用尾随逗号。在考试中,列名必须与表结构中提供的字段名完全一致。
4. Filtering Data with WHERE | 使用WHERE筛选数据
The WHERE clause lets you filter records based on a condition. For example: SELECT * FROM Students WHERE Age > 15; returns only records for students older than 15. Comparison operators like =, <>, <, >, <=, >= are all supported.
WHERE 子句让你根据条件筛选记录。例如:SELECT * FROM Students WHERE Age > 15; 只返回年龄超过 15 岁的学生记录。比较运算符如 =、<>、<、>、<=、>= 均受支持。
You can combine multiple conditions using AND and OR. For instance: SELECT Name, Grade FROM Students WHERE Age = 16 AND Grade = 'A';. Always enclose text values in single quotes.
你可以使用 AND 和 OR 组合多个条件。例如:SELECT Name, Grade FROM Students WHERE Age = 16 AND Grade = 'A';。文本值必须始终用单引号括起来。
5. Using LIKE for Pattern Matching | 使用LIKE进行模式匹配
The LIKE operator is used in a WHERE clause to search for a specified pattern in a text column. The percent sign % represents zero, one, or multiple characters, while the underscore _ represents a single character. For example: SELECT * FROM Students WHERE Name LIKE 'J%'; finds all students whose name starts with J.
LIKE 运算符用在 WHERE 子句中,用于在文本列中搜索指定模式。百分号 % 表示零个、一个或多个字符,下划线 _ 表示单个字符。例如:SELECT * FROM Students WHERE Name LIKE 'J%'; 可找到所有名字以 J 开头的学生。
A common exam question asks for names ending in a certain letter or containing a substring. Use %son for ending with ‘son’, and %a% for containing the letter ‘a’.
常见的考题会要求找出以某个字母结尾或包含某个子串的名字。使用 %son 可找出以 ‘son’ 结尾的名字,使用 %a% 可找出包含字母 ‘a’ 的名字。
6. Sorting Results with ORDER BY | 使用ORDER BY排序结果
To sort the output, add an ORDER BY clause followed by the column name. The default order is ascending (ASC), but you can specify descending order with DESC. Example: SELECT Name, Score FROM Students ORDER BY Score DESC; lists students from highest to lowest score.
要对输出进行排序,可以添加 ORDER BY 子句,后跟列名。默认顺序为升序(ASC),但你也可以用 DESC 指定降序。例如:SELECT Name, Score FROM Students ORDER BY Score DESC; 将学生按成绩从高到低排列。
You can sort by more than one column. ORDER BY Grade ASC, Name DESC sorts primarily by Grade ascending, and then by Name descending when grades are equal.
你可以按多列进行排序。ORDER BY Grade ASC, Name DESC 首先按 Grade 升序排序,当 Grade 相同时再按 Name 降序排序。
In IGCSE papers, the ORDER BY clause always comes after the WHERE clause (if present) and is the last clause in a SELECT statement.
在 IGCSE 考试中,ORDER BY 子句始终放在 WHERE 子句(如果有)之后,并且是 SELECT 语句中的最后一个子句。
7. Inserting New Records with INSERT | 使用INSERT插入新记录
To add a new row to a table, use the INSERT INTO statement. Specify the table name, the columns for which you are providing values, and the corresponding values in the same order. For example: INSERT INTO Students (Name, Age, Grade) VALUES ('Sarah', 16, 'B');.
要向表中添加新行,请使用 INSERT INTO 语句。指定表名、要提供值的列以及按相同顺序排列的对应值。例如:INSERT INTO Students (Name, Age, Grade) VALUES ('Sarah', 16, 'B');。
If you are inserting values for every column in the table, you can omit the column list: INSERT INTO Students VALUES ('John', 15, 'A');. However, this is risky if the table structure changes, so it is safer to list the columns explicitly.
如果要为表中的每一列插入值,可以省略列列表:INSERT INTO Students VALUES ('John', 15, 'A');。然而,如果表结构发生变化,这样做就有风险,因此最好显式列出列名。
Text and date values must be enclosed in single quotes; numeric values should not be quoted.
文本和日期值必须用单引号括起来;数字值不应加引号。
8. Updating Records with UPDATE | 使用UPDATE更新记录
The UPDATE statement modifies existing data. Use SET to specify the column to change and its new value, and WHERE to target which records to update. Omitting the WHERE clause will update every row in the table, which is rarely desired.
UPDATE 语句用于修改现有数据。使用 SET 指定要更改的列及其新值,使用 WHERE 指定要更新哪些记录。省略 WHERE 子句将更新表中的每一行,这很少是我们所期望的。
Example: UPDATE Students SET Grade = 'A' WHERE Name = 'John'; changes John’s grade to A. You can update multiple columns at once: SET Age = 17, Grade = 'B'.
例如:UPDATE Students SET Grade = 'A' WHERE Name = 'John'; 将 John 的成绩更改为 A。你可以一次更新多个列:SET Age = 17, Grade = 'B'。
9. Deleting Records with DELETE | 使用DELETE删除记录
To remove records from a table, use the DELETE FROM command. Always include a WHERE clause to specify which rows to delete. If you omit WHERE, all rows will be deleted, leaving an empty table.
要从表中删除记录,请使用 DELETE FROM 命令。务必包含 WHERE 子句以指定要删除的行。如果省略 WHERE,所有行都将被删除,从而留下一个空表。
Example: DELETE FROM Students WHERE Age < 14; removes all records of students under 14. You must not write DELETE *; the correct syntax is DELETE FROM table_name WHERE condition;.
例如:DELETE FROM Students WHERE Age < 14; 会删除所有 14 岁以下学生的记录。你绝不能写成 DELETE *;正确的语法是 DELETE FROM table_name WHERE condition;。
10. Exam Tips and Common Pitfalls | 考试技巧与常见错误
Always read the question carefully and use the exact table and field names provided. In the CIE exam, you are often given a table schema; your SQL must reflect those names precisely. Do not invent field names.
务必仔细读题,并使用题目提供的准确的表名和字段名。在 CIE 考试中,通常会给出表结构;你的 SQL 必须精确反映这些名称。不要自行编造字段名。
Check your clauses order: SELECT … FROM … WHERE … ORDER BY … ;. This order is strictly enforced. Ensure text values are quoted with single quotes and that comparison operators are used correctly. Using = instead of LIKE for patterns is a common mistake, as is forgetting the WHERE clause in UPDATE and DELETE.
检查子句的顺序:SELECT … FROM … WHERE … ORDER BY … ;。这个顺序是严格要求的。确保文本值用单引号引用,并且比较运算符使用正确。对模式匹配使用 = 而不是 LIKE 是一个常见错误,同样,在 UPDATE 和 DELETE 中忘记添加 WHERE 子句也是常见错误。
Practice writing SQL for different scenarios, including selecting specific columns, filtering with multiple conditions, and sorting. The more you write, the more confident you will be in the exam.
练习针对不同场景编写 SQL,包括选择特定列、使用多个条件进行筛选以及排序。你写得越多,在考试中就越有信心。
Published by TutorHao | IGCSE Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导