🗄️

SQL Templates

SQL query patterns and best practices for common database operations

13 templates

Basic SELECT Query

Fundamental SELECT query patterns with WHERE, ORDER BY, and LIMIT

3 examples 1 code snippets

JOIN Query Patterns

INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN examples

2 examples 1 code snippets

INSERT Data Patterns

Insert single rows, multiple rows, and data from SELECT queries

2 examples 1 code snippets

UPDATE Data Patterns

Update existing records with WHERE conditions and multiple columns

2 examples 1 code snippets

DELETE Data Patterns

Safely delete records with WHERE conditions and cascading deletes

2 examples 1 code snippets

Aggregate Functions (COUNT, SUM, AVG)

Use COUNT, SUM, AVG, MIN, MAX with GROUP BY and HAVING

2 examples 1 code snippets

Subquery Patterns

Nested queries in WHERE, SELECT, and FROM clauses

2 examples 1 code snippets

Common Table Expressions (WITH)

Use WITH clause for readable, reusable temporary result sets

2 examples 1 code snippets

Window Functions (OVER, PARTITION BY)

ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD with window partitions

2 examples 1 code snippets

Transaction Control (BEGIN, COMMIT, ROLLBACK)

Manage database transactions for data consistency and error handling

2 examples 2 code snippets

Index Creation & Optimization

Create indexes to improve query performance and understand index types

2 examples 1 code snippets

CREATE TABLE & Schema Design

Define table schemas with proper data types, constraints, and relationships

2 examples 1 code snippets

Database Migration Patterns

Safe database schema changes with rollback support

2 examples 2 code snippets