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

JDBC SQL Commands CheatSheet

This document is a cheat sheet for JDBC SQL commands, covering CRUD operations, table structure commands, data filtering, joins, grouping and aggregation, sorting, limiting, and transactions. It provides examples for each command, illustrating how to use them effectively in SQL. The summary serves as a quick reference for developers working with SQL in JDBC.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

JDBC SQL Commands CheatSheet

This document is a cheat sheet for JDBC SQL commands, covering CRUD operations, table structure commands, data filtering, joins, grouping and aggregation, sorting, limiting, and transactions. It provides examples for each command, illustrating how to use them effectively in SQL. The summary serves as a quick reference for developers working with SQL in JDBC.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

===============================

JDBC SQL Commands Cheat Sheet


===============================

-----------------------------------
🔄 CRUD Operations
-----------------------------------
1. INSERT INTO - Add new record to a table
Example:
INSERT INTO users (name, age) VALUES ('Alice', 25);

2. SELECT - Retrieve data from a table


Example:
SELECT * FROM users;

3. UPDATE - Modify existing record


Example:
UPDATE users SET age = 26 WHERE name = 'Alice';

4. DELETE - Remove a record


Example:
DELETE FROM users WHERE name = 'Alice';

-----------------------------------
📄 Table Structure Commands
-----------------------------------

5. CREATE TABLE - Create a new table


Example:
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100), age INT);

6. ALTER TABLE - Modify an existing table


Example:
ALTER TABLE users ADD email VARCHAR(100);

7. DROP TABLE - Delete a table entirely


Example:
DROP TABLE users;

8. TRUNCATE TABLE - Delete all records but keep structure


Example:
TRUNCATE TABLE users;

-----------------------------------
🔍 Filtering Data
-----------------------------------

9. WHERE - Filter records


Example:
SELECT * FROM users WHERE age > 25;

10. AND / OR - Combine conditions


Example:
SELECT * FROM users WHERE age > 25 AND city = 'Delhi';

11. BETWEEN - Range filter


Example:
SELECT * FROM users WHERE age BETWEEN 20 AND 30;
12. IN - Match any from list
Example:
SELECT * FROM users WHERE city IN ('Delhi', 'Mumbai');

13. LIKE - Pattern matching


Example:
SELECT * FROM users WHERE name LIKE 'A%';

14. IS NULL / IS NOT NULL - Check for nulls


Example:
SELECT * FROM users WHERE email IS NULL;

-----------------------------------
🧩 Joins
-----------------------------------

15. INNER JOIN - Match records from both tables


Example:
SELECT u.name, o.amount FROM users u INNER JOIN orders o ON u.id = o.user_id;

16. LEFT JOIN - All records from left + matching right


Example:
SELECT u.name, o.amount FROM users u LEFT JOIN orders o ON u.id = o.user_id;

17. RIGHT JOIN - All records from right + matching left


Example:
SELECT u.name, o.amount FROM users u RIGHT JOIN orders o ON u.id = o.user_id;

18. FULL OUTER JOIN - All records from both sides


Example:
SELECT u.name, o.amount FROM users u FULL OUTER JOIN orders o ON u.id =
o.user_id;

-----------------------------------
📊 Grouping & Aggregation
-----------------------------------

19. GROUP BY - Group rows


Example:
SELECT department, COUNT(*) FROM employees GROUP BY department;

20. HAVING - Filter after grouping


Example:
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*)
> 5;

21. COUNT() - Count records


Example:
SELECT COUNT(*) FROM users;

22. SUM() - Total of column values


Example:
SELECT SUM(salary) FROM employees;

23. AVG() - Average of column values


Example:
SELECT AVG(age) FROM users;
24. MAX() / MIN() - Max/Min values
Example:
SELECT MAX(salary), MIN(salary) FROM employees;

-----------------------------------
🎯 Sorting & Limiting
-----------------------------------

25. ORDER BY - Sort records


Example:
SELECT * FROM users ORDER BY age DESC;

26. LIMIT - Restrict number of rows


Example:
SELECT * FROM users LIMIT 10;

-----------------------------------
🧾 Transactions
-----------------------------------

27. BEGIN / START TRANSACTION - Start transaction


(Handled in JDBC via conn.setAutoCommit(false))

28. COMMIT - Save changes


(In JDBC: conn.commit();)

29. ROLLBACK - Undo changes


(In JDBC: conn.rollback();)

===================================
End of JDBC SQL Commands Summary
===================================

You might also like