0% found this document useful (0 votes)
5 views6 pages

Xii SQL

The document provides a comprehensive overview of SQL, including its definition, types of commands (DDL, DML, DQL, DCL), data types, constraints, and various SQL statements such as SELECT, JOIN, and aggregate functions. It also includes examples and practice questions for creating tables, inserting data, and writing queries. Key concepts such as primary keys, foreign keys, and the differences between DELETE, DROP, and TRUNCATE are highlighted for better understanding.

Uploaded by

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

Xii SQL

The document provides a comprehensive overview of SQL, including its definition, types of commands (DDL, DML, DQL, DCL), data types, constraints, and various SQL statements such as SELECT, JOIN, and aggregate functions. It also includes examples and practice questions for creating tables, inserting data, and writing queries. Key concepts such as primary keys, foreign keys, and the differences between DELETE, DROP, and TRUNCATE are highlighted for better understanding.

Uploaded by

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

SQL – Complete Concepts (CBSE Class 12)

🔹 1. What is SQL?
SQL (Structured Query Language) is used to:

 Create database & tables


 Insert, update, delete data
 Retrieve data

🔹 2. Types of SQL Commands


✅ (A) DDL – Data Definition Language
Used to define structure

Command Purpose
CREATE Create table
ALTER Modify table
DROP Delete table

Example:
CREATE TABLE Student(
RollNo INT PRIMARY KEY,
Name VARCHAR(20),
Marks INT
);

✅ (B) DML – Data Manipulation Language


Used to change data

Command Purpose
INSERT Add data
UPDATE Modify data
DELETE Remove data

Example:
INSERT INTO Student VALUES(1, 'Rahul', 85);

UPDATE Student SET Marks = 90 WHERE RollNo = 1;

DELETE FROM Student WHERE RollNo = 1;

✅ (C) DQL – Data Query Language


Used to retrieve data

SELECT * FROM Student;

✅ (D) DCL (Basic idea only)


 GRANT
 REVOKE

🔹 3. Data Types
Type Example
INT 10
VARCHAR(n) 'Hello'
FLOAT 10.5
DATE '2026-03-23'

🔹 4. Constraints
Constraint Meaning
PRIMARY KEY Unique + Not Null
FOREIGN KEY Link between tables
UNIQUE No duplicate
NOT NULL Cannot be empty

Example:
CREATE TABLE Employee(
EmpID INT PRIMARY KEY,
Name VARCHAR(20) NOT NULL,
Salary INT
);
🔹 5. SELECT Statement (Most Important
⭐)
Basic:
SELECT Name FROM Student;

With condition:
SELECT * FROM Student WHERE Marks > 80;

Operators:
 = Equal
 > Greater
 < Less
 LIKE Pattern matching

🔹 6. WHERE Clause Examples


SELECT * FROM Student WHERE Name = 'Rahul';

SELECT * FROM Student WHERE Marks BETWEEN 60 AND 90;

SELECT * FROM Student WHERE Name LIKE 'R%';

🔹 7. ORDER BY (Sorting)
SELECT * FROM Student ORDER BY Marks DESC;

🔹 8. Aggregate Functions
Function Use
COUNT() Count
SUM() Total
AVG() Average
MAX() Highest
MIN() Lowest

Example:
SELECT AVG(Marks) FROM Student;

🔹 9. GROUP BY
SELECT Dept, AVG(Salary)
FROM Employee
GROUP BY Dept;

🔹 10. Joins (Very Important ⭐)


Example Tables:
Student

RollNo Name
1 Rahul
2 Anu

Marks

RollNo Marks
1 85
2 90

INNER JOIN:
SELECT [Link], [Link]
FROM Student
INNER JOIN Marks
ON [Link] = [Link];

LEFT JOIN:
SELECT [Link], [Link]
FROM Student
LEFT JOIN Marks
ON [Link] = [Link];

🔹 11. ALTER Table


ALTER TABLE Student ADD Age INT;
ALTER TABLE Student MODIFY Name VARCHAR(30);

ALTER TABLE Student DROP Age;

🔹 12. DELETE vs DROP vs TRUNCATE


Command Meaning
DELETE Remove specific rows
DROP Delete entire table
TRUNCATE Remove all rows

📝 Important Viva / Theory Points


 Primary key = Unique identifier
 Foreign key = Link tables
 NULL ≠ 0
 LIKE uses % and _

🎯 Practice Questions (Board Level)


🔸 1. Create Table
Create a table EMPLOYEE with:

 ID (Primary Key)
 Name
 Salary
 Department

🔸 2. Insert Data
Insert 5 records into EMPLOYEE

🔸 3. Write Queries
1. Show all employees
2. Show employees with salary > 50000
3. Sort employees by salary
4. Find average salary
5. Count employees

🔸 4. SQL Conditions
SELECT * FROM EMPLOYEE WHERE Name LIKE 'A%';

🔸 5. Join Practice
Create 2 tables:

 STUDENT(RollNo, Name)
 MARKS(RollNo, Marks)

👉 Write JOIN query

🚀 Pro Tips for Boards


 Practice SELECT queries daily
 Focus on:
o WHERE
o GROUP BY
o JOIN
 Avoid syntax mistakes (very common!)

You might also like