0% found this document useful (0 votes)
17 views10 pages

A-Level SQL Notes for Computer Science

Structured Query Language (SQL) is a standardized language used to manage and manipulate relational databases, allowing users to create, read, update, and delete data. Key SQL concepts include various types of commands such as Data Query Language (DQL), Data Definition Language (DDL), and Data Manipulation Language (DML), along with important features like keys, joins, and constraints. SQL databases, like MySQL and PostgreSQL, offer advantages such as efficient data retrieval and strong data integrity, but may require specialist knowledge and can be complex.

Uploaded by

techbelie40
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

A-Level SQL Notes for Computer Science

Structured Query Language (SQL) is a standardized language used to manage and manipulate relational databases, allowing users to create, read, update, and delete data. Key SQL concepts include various types of commands such as Data Query Language (DQL), Data Definition Language (DDL), and Data Manipulation Language (DML), along with important features like keys, joins, and constraints. SQL databases, like MySQL and PostgreSQL, offer advantages such as efficient data retrieval and strong data integrity, but may require specialist knowledge and can be complex.

Uploaded by

techbelie40
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Structured Query Language (SQL) is a standard language used to create, read, update, and

manage data in relational databases.

What SQL Is Used For


SQL allows you to:

 Store data in tables


 Retrieve specific data
 Update existing records
 Delete data
 Control access and permissions
 Define database structure

Common SQL Databases


 MySQL
 PostgreSQL
 Oracle Database
 Microsoft SQL Server
 SQLite

Basic SQL Commands


1. Data Query Language (DQL)

Used to retrieve data.

SELECT * FROM students;


SELECT name, age FROM students WHERE age > 18;

2. Data Definition Language (DDL)

Used to define database structure.

CREATE TABLE students (


id INT PRIMARY KEY,
name VARCHAR(50),
age INT
);

DROP TABLE students;

3. Data Manipulation Language (DML)

Used to modify data.

INSERT INTO students VALUES (1, 'Alice', 20);

UPDATE students
SET age = 21
WHERE id = 1;

DELETE FROM students WHERE id = 1;

4. Data Control Language (DCL)

Used to control access.

GRANT SELECT ON students TO user1;


REVOKE SELECT ON students FROM user1;

5. Transaction Control Language (TCL)

Used to manage transactions.

COMMIT;
ROLLBACK;
SAVEPOINT sp1;

Key SQL Concepts


 Table: Rows and columns storing data
 Primary Key: Uniquely identifies a record
 Foreign Key: Links tables together
 Index: Improves query speed
 JOIN: Combines rows from multiple tables

Example:

SELECT [Link], [Link]


FROM orders
JOIN customers ON orders.customer_id = [Link];
Advantages of SQL
 Easy to learn
 Works with large datasets
 Standardized language
 Secure and reliable

If you want, I can explain SQL joins, normalization, constraints, or provide practice queries
for beginners.

all about sql a level computer science east detailded notse

Below are A-Level Computer Science (UK) – SQL notes, written in exam-ready, detailed
form, suitable for AQA / OCR / Edexcel.
These cover everything typically required at A-Level, with clear definitions, examples, and
key exam points.

STRUCTURED QUERY LANGUAGE


(SQL)
A-Level Computer Science – Detailed Notes

1. What is SQL?
SQL (Structured Query Language) is a standardised language used to manage and
manipulate relational databases.

SQL is used to:

 Create database structures


 Insert, update, delete data
 Retrieve data using queries
 Control user access
 Maintain data integrity
2. Relational Databases
A relational database stores data in tables (relations).

Table Structure

 Rows (records / tuples) – individual entries


 Columns (fields / attributes) – data items

Example table:

StudentID Name Age


1 Alice 20

3. Keys in Databases
Primary Key

 Uniquely identifies each record


 Cannot be NULL
 Must be unique

Example:

StudentID INT PRIMARY KEY

Foreign Key

 Links one table to another


 Refers to a primary key in another table

Example:

StudentID INT REFERENCES Students(StudentID)

4. Types of SQL Commands

4.1 Data Definition Language (DDL)


Used to define the structure of the database.

CREATE

Creates tables or databases.

CREATE TABLE Students (


StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);

DROP

Deletes tables or databases permanently.

DROP TABLE Students;

ALTER

Modifies an existing table.

ALTER TABLE Students ADD Email VARCHAR(100);

4.2 Data Manipulation Language (DML)


Used to manipulate data in tables.

INSERT

Adds new records.

INSERT INTO Students


VALUES (1, 'Alice', 20);

UPDATE

Changes existing data.

UPDATE Students
SET Age = 21
WHERE StudentID = 1;

DELETE

Removes records.

DELETE FROM Students


WHERE StudentID = 1;

⚠️Without a WHERE clause, all records are deleted (exam point).

4.3 Data Query Language (DQL)


Used to retrieve data.

SELECT
SELECT * FROM Students;
SELECT Name, Age FROM Students;

WHERE

Filters records.

SELECT * FROM Students


WHERE Age > 18;

Logical Operators
WHERE Age > 18 AND Name = 'Alice'
WHERE Age = 18 OR Age = 21
WHERE NOT Age = 18

Comparison Operators

Operator Meaning
= Equal
> Greater than
< Less than
Operator Meaning
>= Greater or equal
<= Less or equal
<> Not equal

LIKE

Pattern matching.

SELECT * FROM Students


WHERE Name LIKE 'A%';

ORDER BY

Sorts results.

SELECT * FROM Students


ORDER BY Age DESC;

5. Aggregate Functions
Used to perform calculations on data.

Function Purpose
COUNT() Number of records
SUM() Total
AVG() Average
MAX() Highest value
MIN() Lowest value

Example:

SELECT AVG(Age) FROM Students;

GROUP BY

Groups records.

SELECT Age, COUNT(*)


FROM Students
GROUP BY Age;
HAVING

Filters groups (used with GROUP BY).

SELECT Age, COUNT(*)


FROM Students
GROUP BY Age
HAVING COUNT(*) > 1;

6. JOINs (Very Important for Exams)


Used to retrieve data from multiple tables.

INNER JOIN

Returns matching records only.

SELECT [Link], [Link]


FROM Students
INNER JOIN Courses
ON [Link] = [Link];

LEFT JOIN

Returns all records from the left table.

SELECT [Link], [Link]


FROM Students
LEFT JOIN Courses
ON [Link] = [Link];

RIGHT JOIN

Returns all records from the right table.

7. Constraints
Used to enforce data integrity.
Constraint Purpose
PRIMARY KEY Unique identifier
FOREIGN KEY Links tables
NOT NULL Prevents empty fields
UNIQUE Prevents duplicates
CHECK Restricts values

Example:

Age INT CHECK (Age >= 0)

8. Normalisation (Theory Heavy – Exam Favourite)


Purpose of Normalisation

 Reduce data redundancy


 Improve data integrity
 Prevent update anomalies

First Normal Form (1NF)

 No repeating groups
 Atomic values

Second Normal Form (2NF)

 In 1NF
 No partial dependency

Third Normal Form (3NF)

 In 2NF
 No transitive dependency

9. Advantages of SQL Databases


 Efficient data retrieval
 Strong data integrity
 Supports large datasets
 Standardised language

10. Disadvantages
 Requires specialist knowledge
 Can be complex for large systems
 Performance issues without indexing

11. Exam Tips (VERY IMPORTANT)


 Always include WHERE when updating/deleting
 Use correct SQL keywords (capitalisation helps clarity)
 Know JOINs and GROUP BY
 Be able to write SQL from a scenario
 Know definitions word-for-word

You might also like