Important SQL Commands
1. CREATE DATABASE
Purpose
Used to create a new database.
Syntax
Example
Exam Question Example
Write a SQL command to create a database named LIBRARY.
2. CREATE TABLE
Purpose
Used to create a new table inside a database.
Syntax
column_name datatype,
column_name datatype
);
Example
rollno INT,
name VARCHAR(20),
class VARCHAR(5),
marks INT
);
3. DESC (DESCRIBE)
Purpose
Displays the structure of a table.
Syntax
Example
Output shows
-
column names
-
data types
-
null information
4. INSERT INTO
Purpose
Used to add records into a table.
Syntax
VALUES(value1,value2,value3);
Example
VALUES(101,‘Rahul’,‘XI’,85);
Insert using column names
VALUES(102,‘Riya’,90);
5. SELECT
Purpose
Used to retrieve data from a table.
Syntax
FROM table_name;
Example
6. SELECT *
Purpose
Display all columns from the table.
Syntax
Example
7. DISTINCT
Purpose
Used to remove duplicate values.
Syntax
FROM table_name;
Example
FROM employee;
8. WHERE
Purpose
Used to apply conditions while retrieving data.
Syntax
WHERE condition;
Example
WHERE marks > 80;
9. UPDATE
Purpose
Used to modify existing records.
Syntax
SET column=value
WHERE condition;
Example
SET marks = 88
WHERE rollno = 101;
10. DELETE
Purpose
Used to remove records from a table.
Syntax
WHERE condition;
Example
WHERE rollno = 103;
NOTE : If WHERE clause is omitted, all records will be deleted.
11. ALTER TABLE
Purpose
Used to modify the structure of a table.
Add Column
ADD address VARCHAR(30);
Modify Column
MODIFY name VARCHAR(25);
Drop Column
DROP address;
12. DROP TABLE
Purpose
Used to delete a table permanently.
Syntax
Example
13. ORDER BY
Purpose
Used to sort records.
Syntax
ORDER BY column_name;
Ascending Order
ORDER BY marks ASC;
Descending Order
ORDER BY marks DESC;
14. LIKE
Purpose
Used for pattern matching.
Symbols Used
| Symbol | Meaning |
|---|---|
| % | Any number of characters |
| _ | Single character |
Example
Names starting with R
WHERE name LIKE ‘R%’;
Names ending with a
WHERE name LIKE ‘%a’;
15. BETWEEN
Purpose
Used to select values within a range.
Syntax
WHERE column BETWEEN value1 AND value2;
Example
WHERE marks BETWEEN 70 AND 90;
16. IN
Purpose
Used to match values from a list.
Syntax
WHERE column IN (value1,value2);
Example
WHERE class IN (‘XI’,‘XII’);
17. Logical Operators
Used to combine conditions.
| Operator | Purpose |
|---|---|
| AND | Both conditions must be true |
| OR | At least one condition true |
| NOT | Reverse condition |
Example
WHERE marks > 80 AND class=‘XI’;
Data Manipulation (DML)
Used to add, change, or remove the actual records (rows).
-
INSERT:
INSERT INTO student VALUES (101, 'Rahul', 'XI', 85); -
UPDATE:
UPDATE student SET marks = 88 WHERE rollno = 101;-
⚠️ Note: Always use
WHEREor all rows will be updated!
-
-
DELETE:
DELETE FROM student WHERE rollno = 103;-
⚠️ Note:
DELETE FROM student;removes all data but keeps the table structure.
-
Data Retrieval & Filtering (DQL)
The most common commands for fetching specific information.
The Basic Select
-
SELECT * FROM student;(Show all columns) -
SELECT name, marks FROM student;(Show specific columns) -
SELECT DISTINCT city FROM employee;(Removes duplicate entries)
Filtering with WHERE
-
Relational:
WHERE marks > 80; -
List Match:
WHERE class IN ('XI', 'XII'); -
Range:
WHERE marks BETWEEN 70 AND 90; -
Pattern Matching (LIKE):
-
LIKE 'R%'→ Starts with ‘R’ -
LIKE '%a'→ Ends with ‘a’ -
LIKE '_i%'→ ‘i’ is the second character
-
Sorting & Logic
-
ORDER BY:
ORDER BY marks DESC;(UseASCfor smallest to largest) -
AND / OR: Combine conditions (e.g.,
WHERE marks > 80 AND class = 'XI')
Exam Tips for Students
-
Semicolons: Don’t forget to end every command with
;. -
Quotes: Use single quotes
' 'forVARCHAR,CHAR, andDATEvalues. Numbers do not need quotes. -
DROP vs DELETE:
DROPkills the table;DELETEkills the rows inside the table. -
NULL: Use
IS NULLorIS NOT NULLto check for empty values (never use= NULL).