Cheat sheet · Class 12 · CBSE · Science Computer Science
Structured Query Language (SQL) cheat sheet
The whole chapter on one page: key formulas, facts and the points to remember, for quick revision before a test.
CBSE Class 12 · Computer Science
Cheat sheet
Chapter 10Structured Query Language (SQL)
Query order: SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY.
1. Command Types
| Type | Commands |
|---|---|
| DDL | CREATE, ALTER, DROP |
| DML | INSERT, UPDATE, DELETE, SELECT |
Constraints: PRIMARY KEY, FOREIGN KEY, NOT NULL, UNIQUE, DEFAULT.
2. SELECT Clauses
- WHERE with =, <>, BETWEEN, IN, LIKE ('A%', '_b%'), IS NULL.
- ORDER BY col ASC/DESC.
- DISTINCT removes duplicates.
- Aliases with AS.
3. Functions
- Aggregate: COUNT, SUM, AVG, MAX, MIN.
- String: UPPER, LOWER, LENGTH, SUBSTR, TRIM, INSTR.
- Math: ROUND, POWER, MOD.
- Date: NOW, DATE, MONTH, YEAR, DAYNAME.
4. Grouping & Joins
- GROUP BY groups rows; HAVING filters groups (WHERE filters rows).
- Cartesian product: every row × every row.
- Equi-join: match on a common column; natural join removes the duplicate column.
SELECT dept, AVG(salary) FROM emp GROUP BY dept HAVING AVG(salary) > 50000;
5. Python + MySQL
- mysql.connector.connect(host, user, passwd, database).
- cursor.execute(query); fetchone(), fetchall().
- commit() after INSERT/UPDATE/DELETE.
6. Key Points
- COUNT(*) counts NULL rows; COUNT(col) doesn't.
- DROP removes the table; DELETE removes rows.
- % matches any length; _ one character.
- Use parameterised queries.
Remember: DDL vs DML | WHERE vs HAVING | aggregates | joins
Structured Query Language (SQL): questions and notes
More Class 12 · CBSE · Science Computer Science cheat sheets
Practise Structured Query Language (SQL)
Sign up free to practise the full chapter. Questions you get wrong come back until you've mastered them.
Start practising freeFree to start · No credit card needed