Introduction

SQL (Structured Query Language) is used to interact with relational databases. It helps you to store, retrieve, update, and delete data. SQL is used in almost every industry, from websites to banking systems. If you want to work with data, SQL is a must-have skill. This cheatsheet will give you short and clear definitions, code examples, and key points for the most important SQL topics.

1. SELECT Statement

2. WHERE Clause

3. ORDER BY

4. INSERT INTO

5. UPDATE

6. DELETE

7. CREATE TABLE

8. ALTER TABLE

9. DROP TABLE

10. JOINs

11. GROUP BY

12. HAVING

13. Aggregate Functions

14. DISTINCT

15. BETWEEN, IN, LIKE

16. LIMIT / TOP

17. UNION

18. Subquery

19. Views

20. Indexes

21. Constraints

22. DEFAULT Constraint

23. CASE Statement

24. EXISTS

25. NOT IN vs NOT EXISTS

26. COALESCE and ISNULL

27. Window Functions

28. Common Table Expressions (CTE)

29. Stored Procedures

30. Functions (User-Defined Functions)

31. Transactions

32. ACID Properties

33. Normalization

34. Foreign Key

35. Triggers

36. SET Operators (UNION ALL, INTERSECT, EXCEPT)

37. Backup and Restore

38. TEMPORARY Tables

39. TABLE Variables (SQL Server)

40. MERGE Statement (UPSERT)

41. Recursive CTE

42. JSON Data Handling

43. PIVOT and UNPIVOT

44. ROLLUP and CUBE

45. WITH TIES

46. SEQUENCES

47. IDENTITY vs SEQUENCE

48. LOCKING & ISOLATION LEVELS

49. DEADLOCK

50. EXECUTION PLAN

51. ANALYZE / UPDATE STATISTICS

52. PARTITIONING

53. Sharding

54. Temporal Tables (System-Versioned Tables)