CHAPTER 1: SQL
SQL (Structured Query Language) is a standard language used to store, manipulate, and retrieve data from
relational databases.
1. Basic SQL Commands
CREATE TABLE, INSERT, SELECT, UPDATE, DELETE, DROP, ALTER
2. Creating and Managing Tables
CREATE TABLE Students (...); INSERT INTO Students VALUES (...); UPDATE Students SET Marks=90 WHERE
RollNo=1; DELETE FROM Students WHERE RollNo=2;
3. SELECT Queries
SELECT * FROM Students; SELECT Name, Marks FROM Students WHERE Marks > 80; SELECT * FROM
Students ORDER BY Marks DESC;
4. Aggregate Functions
COUNT(), SUM(), AVG(), MIN(), MAX()
5. GROUP BY and HAVING
SELECT Class, AVG(Marks) FROM Students GROUP BY Class HAVING AVG(Marks) > 80;
6. Joins
INNER JOIN, LEFT JOIN, RIGHT JOIN
7. Keys and Constraints
Primary Key, Foreign Key, Unique, Not Null, Check
8. Practice Queries
1. Display names of students who scored more than 90.
2. Show total number of students in each class.
3. List all students ordered by marks descending.
1
9. 1–5 Mark Questions
1 Mark: What is SQL? Name two DML commands. 2 Mark: Difference between DELETE and DROP. 3 Mark:
Explain GROUP BY and HAVING with examples. 4–5 Mark: Write queries for table EMPLOYEE(EID, Name,
Salary, Dept) to display average salary, employees with salary 30k–50k, and departments with more than 5
employees.
10. Exam Tips & Tricks
Use WHERE before GROUP BY. Use DISTINCT to remove duplicates. NULL is not 0. ORDER BY default is
ascending.