SQL

SQL

  • Structured Query Language.

  • Used to create, retrieve, update and delete data in relational databases.

SELECT

  • Retrieves data.

  • SELECT * returns all fields.

WHERE

  • Filters records using conditions.

  • Uses =, >, <, >=, <=, <>.

AND

  • Both conditions must be true.

OR

  • At least one condition must be true.

ORDER BY

  • Sorts records.

  • ASC = ascending.

  • DESC = descending.

INSERT INTO

  • Adds new records.

UPDATE

  • Modifies existing records.

  • Usually used with WHERE.

DELETE

  • Removes records.

  • Usually used with WHERE.

LIKE

  • Pattern matching.

  • % represents any number of characters.

Aggregate Functions

  • COUNT() = number of records.

  • SUM() = total.

  • AVG() = average.

  • MAX() = largest value.

  • MIN() = smallest value.


OCR SQL Commands to Memorise

SELECT * FROM Student;
SELECT * FROM Student WHERE Age = 16;
SELECT * FROM Student WHERE Age > 16;
SELECT * FROM Student ORDER BY Name ASC;
INSERT INTO Student VALUES (101,'Ali',16);
UPDATE Student
SET Age = 17
WHERE StudentID = 101;
DELETE FROM Student
WHERE StudentID = 101;
SELECT COUNT(*)
FROM Student;