SQL Templates
SQL query patterns and best practices for common database operations
Basic SELECT Query
Fundamental SELECT query patterns with WHERE, ORDER BY, and LIMIT
JOIN Query Patterns
INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN examples
INSERT Data Patterns
Insert single rows, multiple rows, and data from SELECT queries
UPDATE Data Patterns
Update existing records with WHERE conditions and multiple columns
DELETE Data Patterns
Safely delete records with WHERE conditions and cascading deletes
Aggregate Functions (COUNT, SUM, AVG)
Use COUNT, SUM, AVG, MIN, MAX with GROUP BY and HAVING
Subquery Patterns
Nested queries in WHERE, SELECT, and FROM clauses
Common Table Expressions (WITH)
Use WITH clause for readable, reusable temporary result sets
Window Functions (OVER, PARTITION BY)
ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD with window partitions
Transaction Control (BEGIN, COMMIT, ROLLBACK)
Manage database transactions for data consistency and error handling
Index Creation & Optimization
Create indexes to improve query performance and understand index types
CREATE TABLE & Schema Design
Define table schemas with proper data types, constraints, and relationships
Database Migration Patterns
Safe database schema changes with rollback support