0% found this document useful (0 votes)
3 views2 pages

Class12 SQL 3page Short Notes

This document provides a concise overview of SQL commands, including their types and examples for quick revision for Class 12 Computer Science. It covers DDL, DML, DCL, and TCL commands, along with clauses, aggregate functions, and additional topics like primary and foreign keys. Each command is accompanied by a brief explanation and example code.

Uploaded by

js0834950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Class12 SQL 3page Short Notes

This document provides a concise overview of SQL commands, including their types and examples for quick revision for Class 12 Computer Science. It covers DDL, DML, DCL, and TCL commands, along with clauses, aggregate functions, and additional topics like primary and foreign keys. Each command is accompanied by a brief explanation and example code.

Uploaded by

js0834950
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Class 12 Computer Science – SQL Short Notes

(CBSE 2025)
All SQL commands with 1-line explanation and example code for 3-page quick revision.

1. SQL – Structured Query Language used to manage relational


databases.
SELECT * FROM Student;

2. Types of SQL Commands


Type Meaning Examples
DDL Defines database/table structure CREATE, ALTER, DROP
DML Manages data in tables INSERT, UPDATE, DELETE, SELECT
DCL Controls access to data GRANT, REVOKE
TCL Manages transactions COMMIT, ROLLBACK

3. DDL Commands
CREATE TABLE – creates a new table.
CREATE TABLE Student(RollNo INT, Name VARCHAR(20), Marks INT);

ALTER TABLE – modifies table structure.


ALTER TABLE Student ADD Age INT;

DROP TABLE – deletes a table.


DROP TABLE Student;

RENAME TABLE – renames an existing table.


RENAME TABLE Student TO Class12;

TRUNCATE TABLE – removes all data but keeps structure.


TRUNCATE TABLE Student;

4. DML Commands
INSERT – adds records.
INSERT INTO Student VALUES(101, 'Aman', 88);

UPDATE – modifies records.


UPDATE Student SET Marks=95 WHERE RollNo=101;
DELETE – removes records.
DELETE FROM Student WHERE RollNo=101;

SELECT – retrieves records.


SELECT Name, Marks FROM Student;

5. Clauses
Clause Purpose Example
WHERE Filters rows SELECT * FROM Student WHERE Marks>80;
ORDER BY Sorts result SELECT * FROM Student ORDER BY Marks DESC;
GROUP BY Groups same values SELECT Grade, COUNT(*) FROM Student GROUP BY Grade
HAVING Filters grouped data SELECT Grade, AVG(Marks) FROM Student GROUP BY Gra
DISTINCT Removes duplicates SELECT DISTINCT Grade FROM Student;

6. Aggregate Functions
Function Purpose Example
COUNT() Counts rows SELECT COUNT(*) FROM Student;
SUM() Total of column SELECT SUM(Marks) FROM Student;
AVG() Average value SELECT AVG(Marks) FROM Student;
MAX() Highest value SELECT MAX(Marks) FROM Student;
MIN() Lowest value SELECT MIN(Marks) FROM Student;

7. Additional Topics
Topic Meaning Example
PRIMARY KEY Uniquely identifies records CREATE TABLE S(RollNo INT PRIMARY KEY, Name VAR
FOREIGN KEY Links tables FOREIGN KEY(ClassID) REFERENCES Class(ID);
NULL Missing/unknown data SELECT * FROM Student WHERE Grade IS NULL;
BETWEEN Checks range SELECT * FROM Student WHERE Marks BETWEEN 70 AN
IN Matches list values SELECT * FROM Student WHERE Grade IN('A','B');
LIKE Pattern match SELECT * FROM Student WHERE Name LIKE 'A%';

Tip: Always end SQL statements with a semicolon (;) and remember keywords are
case-insensitive.

You might also like