Tag

sql prompts

Browse prompts tagged sql. Use this page to find templates tied to a specific workflow, method, platform, or content pattern.

3 prompts

Optimize A Slow SQL Query

Paste the slow query along with the database engine, approximate table sizes, current execution time, and any existing indexes, and this prompt diagnoses the real bottleneck — a full table scan, a missing index, an unnecessary join — before rewriting the query for performance. It proposes concrete CREATE INDEX statements, estimates the expected speedup, and suggests an alternative like a materialized view or pre-aggregation when a rewrite alone won't be enough, showing before-and-after versions with an explanation for each change.

Write A SQL Query For Analysis

Describe the database engine, the available tables with their columns and relationships, the analysis you need in plain English, and whether to optimize for large tables or readability, and this prompt writes the production-ready SQL query to get there. It handles nulls sensibly, uses CTEs to keep complex logic readable, comments any non-obvious steps, and returns business-friendly column names instead of raw database_column_names — useful whenever you know the analysis you want but not the SQL to write it.

Write Parameterized Dashboard SQL Queries

List the filter dimensions users can apply, the key metrics shown, the drill-down hierarchy, the comparison periods needed, the database engine, and the relevant tables, and this prompt writes the parameterized SQL query layer behind an interactive dashboard. Each panel's query accepts filter parameters using {{parameter_name}} syntax, returns data shaped for its visualization, is written for sub-second interactive response, and handles edge cases like empty filters meaning "all data" or invalid date ranges.