0% found this document useful (0 votes)
4 views3 pages

SQL

This document provides a comprehensive overview of SQL, including command types (DDL, DML, DQL), clauses (WHERE, ORDER BY, DISTINCT), operators, aggregate functions, and data types. It also covers constraints, pattern matching with LIKE, and differences between DELETE and TRUNCATE. Additionally, it highlights common errors and the execution order of SQL statements.
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)
4 views3 pages

SQL

This document provides a comprehensive overview of SQL, including command types (DDL, DML, DQL), clauses (WHERE, ORDER BY, DISTINCT), operators, aggregate functions, and data types. It also covers constraints, pattern matching with LIKE, and differences between DELETE and TRUNCATE. Additionally, it highlights common errors and the execution order of SQL statements.
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

📘 SQL REVISION

🔹 SQL = Structured Query Language


🔹 Works on tables (row s + columns)
🔹 COMMAND TYPES
DDL → CREATE , ALTER, DROP, TRUNCATE
DML → INSERT, UPDATE , DELETE
DQL → SELECT
CREATE TABLE Student (RollNo INT, Name VARCHAR(20),
Marks INT);
INSERT INTO Student VALUES (1 ,'A',90);
UPDATE Student SET Marks=95 WHERE RollNo=1;
DELETE FROM Student WHERE RollNo=1;
SELECT * FROM Student;
SELECT Name,Marks FROM Student WHERE Marks>80;
🔹 CL AUSES
WHERE → SELECT * FROM Student WHERE Marks>80
ORDER BY → SELECT * FROM Student ORDER BY Marks DESC
DISTINCT → SELECT DISTINCT Marks FROM Student
🔹 OPERATORS
=, >, <, >=, <=, <>
AND, OR, NOT
SELECT * FROM Student
WHERE Marks>80 AND Name='A';
🔹 AGGREGATE FUNCTIONS
COUNT() → row s
SUM() → total
AVG() → average
MAX() → highest
MIN() → lowest
SELECT AVG(Marks) FROM Student;
🔹 GROUPING
GROUP BY → grouping
HAVING → group condition
SELECT Marks,COUNT() FROM Student GROUP BY Marks;
SELECT Marks,COUNT() FROM Student GROUP BY Marks
HAVING COUNT(*)>1;
🔹 DATA TYPES
INT, FLOAT, DATE
VARCHAR(n) → variable
CHAR(n) → fixed
🔹 CONSTRAINT S
PRIMARY KEY → unique + not null
NOT NULL → cannot be empty
UNIQUE → no duplicates
DEFAULT → auto value
CHECK → condition
Example: Marks INT CHECK(Marks>=0)

🔹 LIKE (pattern)
'A%' → starts with A
'%A' → ends with A
'%A%' → contains A
'_' → single character
🔹 BETWEEN
Marks BETWEEN 50 AND 80
🔹 IN
Marks IN (50,60,70)
🔹 NULL
IS NULL / IS NOT NULL
(NULL ≠ 0)

🔹 ALTER
ADD → ALTER TABLE Student ADD Age INT
DROP → ALTER TABLE Student DROP Age
MODIFY → ALTER TABLE Student MODIFY Name
VARCHAR(50)
🔹 DIFFERENCES
DELETE → selected row s
TRUNCATE → full table
WHERE → before grouping
HAVING → af ter grouping

🔹 EXECUTION ORDER
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER
BY
🔹 QUICK REVISION
SELECT → fetch
WHERE → filter
GROUP BY → group
HAVING → group condition
INSERT → add
UPDATE → modif y
DELETE → remove
🔹 FOCUS
✔ SELECT queries
✔ Conditions
✔ Functions
✔ Errors
✔ Dif ferences

🔹 COMMON ERRORS
❌ INSERT INTO Student VALUES (1 ,'A')
✔ Missing values
❌ UPDATE Student SET Marks=100
✔ Updates all row s
❌ WHERE Marks = NULL
✔ Use IS NULL
❌ SELECT Name Marks FROM Student
✔ Missing comma

You might also like