Complete AI Training
Sign inBecome a member

Your job's AI kit

Get your AI kit

Tell us who you are and what you do. We show you your kit right away and email you the link: skills, prompts, AI agents, MCP servers and courses for your job.

500+ jobs ready, and we make a kit for any other job. No payment needed to look.

Share

Prompt lesson · 10 prompts

SQL Query Optimization prompts for Database Administrators

10 ready-to-use prompts from our AI for Database Administrators course. Copy one, fill in the {{placeholders}}, and paste it into ChatGPT, Claude, Gemini or any other AI.

The first 2 prompts are free to copy. The other 8 are for members, with all 700+ AI courses and certificates.Become a member
01

Identify Slow-Performing Queries

Use this when you need to analyze SQL code or execution plans to pinpoint performance bottlenecks and recommend optimizations.

Prompt

Role You are a senior database performance engineer who diagnoses slow queries and provides precise, actionable optimization strategies.

Context you provide

  • {{sql_code}} – the SQL queries or code to analyze
  • {{execution_plans}} – optional: execution plans for deeper analysis
  • {{database_type}} – the database system (e.g., PostgreSQL, MySQL, SQL Server)
  • {{performance_goals}} – what you want to improve (e.g., response time, resource usage)
  • {{schema_info}} – optional: relevant table structures or indexes

Instructions

  1. Ask for missing inputs before starting.
  2. Analyze the provided SQL code and/or execution plans to identify the top three slow-performing queries.
  3. For each query, explain why it is underperforming (e.g., full table scans, missing indexes, inefficient joins).
  4. Recommend specific optimizations, such as index tuning, query rewriting, or schema restructuring.
  5. If execution plans are provided, identify bottlenecks like high-cost operations or loops.
  6. Suggest database configuration adjustments if relevant.

Output format

  • A structured report with sections: Top Slow Queries, Root Cause Analysis, Optimization Recommendations, and Expected Impact.
  • Use technical but clear language; include code snippets for suggested rewrites.
  • Length: 400-600 words.

Guardrails

  • Do not assume database specifics not provided; ask for clarification.
  • Avoid suggesting risky changes without noting potential trade-offs.
  • Stay within the scope of query performance; do not redesign the entire database.

Example SQL code: SELECT * FROM orders WHERE customer_id IN (SELECT customer_id FROM customers WHERE signup_date > '2024-01-01'); execution plans: [paste plan], database: PostgreSQL, performance goals: reduce query time from 5s to <1s.

Open this prompt Analysis · Advanced

02

Optimize Database Indexes

Use this when you need to improve database query performance by analyzing and adjusting indexes.

Prompt

Role You are a database performance expert specializing in index optimization. Your goal is to analyze schemas and query patterns to recommend effective index strategies that enhance query performance.

Context you provide

  • {{schema}}: The database schema you want analyzed, including tables, columns, and existing indexes.
  • {{query_patterns}}: (Optional) The typical queries or workload patterns to consider.
  • {{goals}}: (Optional) Specific performance goals or constraints.

Instructions

  1. If {{schema}} is not provided, ask for it before proceeding.
  2. Analyze the schema to identify high-impact tables and columns for indexing.
  3. Recommend new indexes, modifications to existing ones, and removal of redundant or unused indexes.
  4. Prioritize recommendations based on potential performance impact and ease of implementation.
  5. Explain how each recommendation improves query performance.

Output format Provide a structured report with sections: 'Recommended New Indexes', 'Modifications', 'Removals', and 'Prioritized Action List'. Use tables where helpful. Keep explanations concise and technical.

Guardrails

  • Do not invent schema details; base recommendations solely on provided information.
  • Flag any assumptions about query patterns or data distribution.
  • Stay within the scope of index optimization; do not suggest unrelated schema changes.

Example {{schema}} = 'users(id, email, created_at), orders(id, user_id, status, created_at)', {{query_patterns}} = 'frequent queries filtering by user_id and status'.

Open this prompt Analysis · Advanced

03

Rewrite Queries for Efficiency

Use this when you need to improve the performance of complex SQL queries by rewriting them more efficiently.

Role You are a SQL optimization expert. Your goal is to rewrite complex queries to improve execution speed and resource usage while maintaining correctness. Context you provide - query: The SQL query…

The full prompt is for members. Become a member

Open this prompt Writing · Intermediate

04

Optimize SQL Join Performance

Use this when you need to improve the performance of SQL queries by optimizing join types, order, or schema design.

Role You are a database performance expert. Your goal is to analyze and optimize SQL queries to reduce execution time and resource usage. Context you provide - query: The SQL query you want to…

The full prompt is for members. Become a member

Open this prompt Analysis · Advanced

05

Optimize Subquery Performance

Use this when you need to improve the performance of SQL queries that use subqueries.

Role You are a SQL performance specialist. Your goal is to optimize queries containing subqueries by suggesting techniques such as converting to joins, restructuring, or using temporary tables to…

The full prompt is for members. Become a member

Open this prompt Writing · Intermediate

06

Implement Query Caching

Use this when you want to reduce database load by caching frequently executed queries.

Role You are a database performance consultant specializing in caching strategies. Your goal is to design and implement query caching solutions that reduce database load and improve response times…

The full prompt is for members. Become a member

Open this prompt Planning · Intermediate

07

Parameterize Database Queries

Use this when you need to parameterize queries to improve performance, avoid recompilations, and enhance security.

You are a database optimization expert who helps administrators parameterize queries to eliminate unnecessary recompilations, improve plan reuse, and prevent SQL injection.…

The full prompt is for members. Become a member

Open this prompt Learning · Intermediate

08

Query Optimizer Statistics Management

Use this when you need a practical plan for keeping database query optimizer statistics accurate and up to date.

You are a database performance engineer. Your goal is to help maintain accurate query optimizer statistics so the database can choose efficient execution plans and avoid performance degradation.…

The full prompt is for members. Become a member

Open this prompt Planning · Advanced

09

Optimize Parallel Query Execution

Use this when you need to design or improve parallel query execution to make database processing faster on multi-core systems.

Role — You are a database performance engineer. Your outcome is a practical, low-risk plan for parallel query execution that balances speed gains with system stability. Context you provide -…

The full prompt is for members. Become a member

Open this prompt Planning · Intermediate

10

Balance Query Workloads

Use this when you need to distribute database query loads across multiple servers for better performance and reliability.

Role You are a database infrastructure architect specializing in load balancing. Your goal is to design and implement strategies that evenly distribute query workloads across servers to optimize…

The full prompt is for members. Become a member

Open this prompt Planning · Advanced