⭐ 1.
Different Types of SQL Commands
Category Full Form Purpose Examples
(Min 2 each)
DDL Data Definition Defines or CREATE, ALTER,
Language modifies DROP,
structure of DB TRUNCATE,
objects RENAME
DML Data Manipulates INSERT,
Manipulation data stored in UPDATE,
Language tables DELETE, MERGE
DQL Data Query Retrieves data SELECT (only
Language command)
DCL Data Control Provides GRANT, REVOKE
Language security/access
control
TCL Transaction Manages COMMIT,
Control transactions in ROLLBACK,
Language DB SAVEPOINT, SET
TRANSACTION
⭐ 2. Keys in SQL
Key Description
Primary Key Uniquely identifies each row;
cannot be NULL & must be
unique.
Foreign Key A field that refers to the
Primary key of another table to
maintain relationships.
Candidate Key All possible attributes that can
be chosen as a primary key.
Alternate Key Candidate keys that are not
selected as the primary key.
Composite Key A primary key formed using two
or more columns.
Unique Key Ensures all values in the
column are unique but allows
one NULL.
Super Key A set of columns that can
uniquely identify each row
(superset of candidate keys).
⭐ 3. Aggregate Functions / Operators
Function Description
SUM(column) Returns total sum of values.
COUNT(column) Counts number of rows.
AVG(column) Returns average values.
MIN(column) Returns minimum value.
MAX(column) Returns maximum value.
⭐ 4. Differences
Comparison Explanation
DROP vs DELETE vs DROP – removes the whole
TRUNCATE table with structure.
TRUNCATE – removes all records
but keeps structure (cannot be
rolled back).
DELETE – removes selected
rows using WHERE (can be
rolled back).
HAVING vs GROUP BY GROUP BY – groups rows based
on a column.
HAVING – filter applied after
grouping (works with aggregate
functions).
ALTER vs UPDATE ALTER – modifies table structure
(add/modify/remove column).
UPDATE – modifies table data.
File System vs DBMS vs File System – no data
RDBMS integrity, security, redundancy
very high.
DBMS – data stored in files;
limited relationships & security.
RDBMS – uses tables &
relationships; constraints, ACID
properties, SQL support.
Insert, Update & Delete Occur due to bad un-
Anomaly normalized design:
Insert anomaly – cannot
insert data because another
field is missing.
Update anomaly – need to
update same data in many
places.
Delete anomaly – deleting
one record deletes other
important data too.
Primary Key vs Unique Key Primary Key – unique + NOT
NULL (only one per table).
Unique Key – unique but
allows one NULL (multiple can
exist in table).
⭐ 5. Sample SQL Queries
✔️ Create Table
CREATE TABLE Students (
RollNo INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Marks INT
);
✔️ Insert Data
INSERT INTO Students (RollNo, Name, Age, Marks)
VALUES (1, 'Adaa', 20, 85);
INSERT INTO Students VALUES (2, 'Rohan', 21, 90);
✔️ Select / View Data
SELECT * FROM Students;
SELECT Name, Marks FROM Students WHERE Marks > 80;
✔️ Alter Table (Modify Structure)
ALTER TABLE Students ADD Email VARCHAR(100);
ALTER TABLE Students MODIFY Age INT NOT NULL;
✔️ Update Data
UPDATE Students SET Marks = 95 WHERE RollNo = 1;
💡 Optional Aggregation Query Example
SELECT AVG(Marks) AS AverageMarks FROM Students;