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

SQL Keywords With Examples

This document provides a comprehensive reference of SQL keywords organized by category, including examples for each keyword. It covers various aspects of SQL such as Data Query Language, Data Manipulation Language, Data Definition Language, and more, making it suitable for academic exams and interview preparation. The document serves as a practical guide for understanding and using SQL effectively.

Uploaded by

boaboa3026
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 Keywords With Examples

This document provides a comprehensive reference of SQL keywords organized by category, including examples for each keyword. It covers various aspects of SQL such as Data Query Language, Data Manipulation Language, Data Definition Language, and more, making it suitable for academic exams and interview preparation. The document serves as a practical guide for understanding and using SQL effectively.

Uploaded by

boaboa3026
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 Keywords – Complete Exam-Oriented

Reference with Examples

This document compiles commonly used and exam-relevant SQL keywords, grouped by category,
with simple examples demonstrating their usage. This is suitable for academic exams, MCQs, and
interview preparation.

1. Data Query Language (DQL)

Keyword Example Usage


SELECT <font size=9><i>SELECT name FROM Employees;</i></font>
DISTINCT <font size=9><i>SELECT DISTINCT department FROM Employees;</i></font>
FROM <font size=9><i>SELECT * FROM Employees FROM dual;</i></font>

2. Data Manipulation Language (DML)

Keyword Example Usage


INSERT <font size=9><i>INSERT INTO Employees VALUES (1, 'Asha', 50000);</i></font>
UPDATE <font size=9><i>UPDATE Employees SET salary = 60000 WHERE id = 1;</i></font>
DELETE <font size=9><i>DELETE FROM Employees WHERE id = 1;</i></font>

3. Data Definition Language (DDL)

Keyword Example Usage


CREATE <font size=9><i>CREATE TABLE Emp(id INT, name VARCHAR(50));</i></font>
ALTER <font size=9><i>ALTER TABLE Emp ADD salary INT;</i></font>
DROP <font size=9><i>DROP TABLE Emp;</i></font>
TRUNCATE <font size=9><i>TRUNCATE TABLE Emp;</i></font>
RENAME <font size=9><i>RENAME Emp TO Employees;</i></font>

4. Constraints

Keyword Example Usage


PRIMARY KEY <font size=9><i>id INT PRIMARY KEY</i></font>
FOREIGN KEY <font size=9><i>FOREIGN KEY (dept_id) REFERENCES Dept(id)</i></font>
UNIQUE <font size=9><i>email VARCHAR(50) UNIQUE</i></font>
CHECK <font size=9><i>age INT CHECK (age >= 18)</i></font>
DEFAULT <font size=9><i>status VARCHAR(10) DEFAULT 'ACTIVE'</i></font>

5. Filtering & Conditions

Keyword Example Usage


WHERE <font size=9><i>SELECT * FROM Emp WHERE salary > 40000;</i></font>
AND <font size=9><i>WHERE salary > 40000 AND dept = 'IT'</i></font>
OR <font size=9><i>WHERE dept = 'IT' OR dept = 'HR'</i></font>
NOT <font size=9><i>WHERE NOT dept = 'IT'</i></font>
IN <font size=9><i>WHERE dept IN ('IT','HR')</i></font>
BETWEEN <font size=9><i>WHERE salary BETWEEN 30000 AND 60000</i></font>
LIKE <font size=9><i>WHERE name LIKE 'A%'</i></font>
IS NULL <font size=9><i>WHERE manager_id IS NULL</i></font>

6. Aggregation & Grouping

Keyword Example Usage


GROUP BY <font size=9><i>GROUP BY department</i></font>
HAVING <font size=9><i>HAVING COUNT(*) > 5</i></font>
COUNT <font size=9><i>SELECT COUNT(*) FROM Emp;</i></font>
SUM <font size=9><i>SELECT SUM(salary) FROM Emp;</i></font>
AVG <font size=9><i>SELECT AVG(salary) FROM Emp;</i></font>
MIN <font size=9><i>SELECT MIN(salary) FROM Emp;</i></font>
MAX <font size=9><i>SELECT MAX(salary) FROM Emp;</i></font>

7. Joins

Keyword Example Usage


INNER JOIN <font size=9><i>SELECT * FROM A INNER JOIN B ON [Link]=[Link];</i></font>
LEFT JOIN <font size=9><i>SELECT * FROM A LEFT JOIN B ON [Link]=[Link];</i></font>
RIGHT JOIN <font size=9><i>SELECT * FROM A RIGHT JOIN B ON [Link]=[Link];</i></font>
FULL JOIN <font size=9><i>SELECT * FROM A FULL JOIN B ON [Link]=[Link];</i></font>
ON <font size=9><i>JOIN Dept ON Emp.dept_id = [Link]</i></font>

8. Subqueries & Set Operators

Keyword Example Usage


EXISTS <font size=9><i>WHERE EXISTS (SELECT 1 FROM Dept)</i></font>
ANY <font size=9><i>WHERE salary > ANY (SELECT salary FROM Emp)</i></font>
ALL <font size=9><i>WHERE salary > ALL (SELECT salary FROM Emp)</i></font>
UNION <font size=9><i>SELECT id FROM A UNION SELECT id FROM B</i></font>
UNION ALL <font size=9><i>SELECT id FROM A UNION ALL SELECT id FROM B</i></font>
INTERSECT <font size=9><i>SELECT id FROM A INTERSECT SELECT id FROM B</i></font>
EXCEPT <font size=9><i>SELECT id FROM A EXCEPT SELECT id FROM B</i></font>

9. Transaction Control Language (TCL)

Keyword Example Usage


COMMIT <font size=9><i>COMMIT;</i></font>
ROLLBACK <font size=9><i>ROLLBACK;</i></font>
SAVEPOINT <font size=9><i>SAVEPOINT sp1;</i></font>

10. Views & Indexes

Keyword Example Usage


CREATE VIEW <font size=9><i>CREATE VIEW v_emp AS SELECT * FROM Emp;</i></font>
DROP VIEW <font size=9><i>DROP VIEW v_emp;</i></font>
CREATE INDEX <font size=9><i>CREATE INDEX idx_emp ON Emp(id);</i></font>
DROP INDEX <font size=9><i>DROP INDEX idx_emp;</i></font>

11. Miscellaneous / Utility Keywords

Keyword Example Usage


AS <font size=9><i>SELECT salary AS income FROM Emp;</i></font>
CASE <font size=9><i>CASE WHEN salary>50000 THEN 'High' END</i></font>
WHEN <font size=9><i>WHEN salary>50000 THEN 'High'</i></font>
THEN <font size=9><i>THEN 'High'</i></font>
ELSE <font size=9><i>ELSE 'Low'</i></font>
END <font size=9><i>END AS salary_level</i></font>
ORDER BY <font size=9><i>ORDER BY salary DESC</i></font>
ASC <font size=9><i>ORDER BY salary ASC</i></font>
DESC <font size=9><i>ORDER BY salary DESC</i></font>
LIMIT <font size=9><i>SELECT * FROM Emp LIMIT 5;</i></font>

You might also like