Notes · Class 12 · CBSE · Science Computer Science

Structured Query Language (SQL) notes

Revision notes for the chapter: the key points, definitions and exam tips to remember.

SQL is the standard language to create and query relational databases (MySQL).

COMMAND TYPES

  • DDL: CREATE, ALTER, DROP. DML: INSERT, UPDATE, DELETE. Query: SELECT.

DATA TYPES AND CONSTRAINTS

  • CHAR(n) (fixed), VARCHAR(n), INT, FLOAT, DATE.
  • NOT NULL, UNIQUE, DEFAULT, PRIMARY KEY, FOREIGN KEY.

EXAMPLES

  • CREATE TABLE Student (RollNo INT PRIMARY KEY, Name VARCHAR(20), Marks INT);
  • INSERT INTO Student VALUES (1, 'Asha', 92);
  • UPDATE Student SET Marks = 95 WHERE RollNo = 1;
  • DELETE FROM Student WHERE Marks < 33;
  • ALTER TABLE Student ADD City VARCHAR(20);

SELECT

  • SELECT Name, Marks FROM Student WHERE Marks > 80 ORDER BY Marks DESC;
  • DISTINCT, BETWEEN, IN, LIKE ('A%' starts with A, '_a%' second letter a), IS NULL.
  • Aggregate functions: COUNT, SUM, AVG, MAX, MIN.
  • GROUP BY with HAVING (filter groups).
  • Single-row functions: UPPER, LOWER, LENGTH, SUBSTR, ROUND, NOW, YEAR.

JOINS

  • Cartesian product, equi-join (WHERE A.id = B.id), natural join.
Memory hook: "WHERE filters rows, HAVING filters groups."

Structured Query Language (SQL): practice questionsStructured Query Language (SQL) cheat sheet

More Class 12 · CBSE · Science Computer Science notes

Practise Structured Query Language (SQL)

Sign up free to practise the full chapter after revising. Questions you get wrong come back until you've mastered them.

Start practising free

Free to start · No credit card needed