Worksheets › Class 12 › Structured Query Language (SQL) › Cheat sheet

Class 12 Structured Query Language (SQL): cheat sheet

CBSE Computer Science. SQL’s DDL and DML commands, data types and constraints, SELECT with WHERE, BETWEEN, IN, LIKE, DISTINCT and ORDER BY, and UPDATE and DELETE.

Open the printable cheat sheetPractice worksheet

Key ideas

Remember

The order of a querySELECT columns FROM table WHERE condition ORDER BY column
BETWEENSalary BETWEEN 30000 AND 50000 means Salary >= 30000 AND Salary <= 50000
LIKE (% any run, _ one character)'A%' begins with A; '%a' ends with a; '_a%' has a second letter a
NULLWHERE Bonus IS NULL, never Bonus = NULL
ALTER TABLE … ADDa new column, in which the existing rows get NULL
DROP or DELETEDROP TABLE removes the table itself (DDL); DELETE FROM removes rows and keeps the table (DML)

Watch out

Worked example

Table: EMPLOYEE EmpNo | Name | Dept | Salary | Bonus E1 | Priya | IT | 73000 | 2000 E2 | Arjun | IT | 31000 | 9500 E3 | Vikram | HR | 84000 | 2500 E4 | Meera | IT | 69000 | NULL E5 | Rohan | Accounts | 67000 | 2000 E6 | Zoya | HR | 60000 | 10000 E7 | Dev | Accounts | 45000 | 10000 UPDATE EMPLOYEE SET Salary = Salary + 5000 WHERE Dept NOT IN ('Accounts', 'IT') AND Salary BETWEEN 31000 AND 73000; (a) How many rows does this statement change? (b) What does SELECT SUM(Salary) FROM EMPLOYEE; return after it? (c) Is it a DDL or DML command? Why?

Working: rows where Dept NOT IN ('Accounts', 'IT') AND Salary BETWEEN 31000 AND 73000

Answer: (a) 1; (b) 434000; (c) DML: it changes the data in the table, not its structure.

Practise Structured Query Language (SQL)

Revise with this page, then practise: every Structured Query Language (SQL) sheet in the app is new, with an answer key and working.

Coming soon for Android and iPhone.