Databases 11 min read

Supercharge Your SQL Workflows with DeepSeek Prompt Templates

This guide presents a comprehensive collection of DeepSeek prompt templates for MySQL, covering SQL generation, optimization, data analysis, database administration, debugging, and advanced features, enabling beginners and seasoned developers alike to craft accurate queries, improve performance, and resolve errors efficiently.

dbaplus Community
dbaplus Community
dbaplus Community
Supercharge Your SQL Workflows with DeepSeek Prompt Templates

1. SQL Generation Prompts

These prompts help you quickly generate various types of SQL statements by describing the desired query in natural language.

Basic query generation

I am using a MySQL database. Please generate a SQL query that selects from [table_name] where [condition] holds, orders the result by [column_name] in descending order, and returns only the first 10 rows.

Multi‑table JOIN query

I am using a MySQL database. Based on the following table structures, generate a LEFT JOIN query:
Table A: id, name, dept_id
Table B: dept_id, dept_name
The result should include all employees and their department names, including employees without a department.

Complex sub‑query

I am using a MySQL database. Generate a SQL statement that calculates the total order amount for each customer and returns only those customers whose total exceeds the overall average.

Time‑range aggregation

I am using a MySQL database. Generate a query that, for the period January‑June 2023, computes daily sales totals and then aggregates them by month.

Dynamic CASE‑WHEN branching

I am using a MySQL database. Generate a SQL statement that classifies users by age into three groups: "Youth" (<30), "Middle‑age" (30‑50), and "Senior" (>50), and counts the number of users in each group.

2. SQL Optimization Prompts

Use these prompts to obtain performance‑related advice from DeepSeek.

Index recommendation

I am using a MySQL database. Analyze the following query and suggest which indexes should be created:
SELECT * FROM orders WHERE user_id = 100 AND status = 'paid';

Explain execution plan

I am using a MySQL database. Explain the EXPLAIN output for the given query and point out potential performance bottlenecks. [Paste EXPLAIN text here]

Slow‑query optimization

I am using a MySQL database. The following query runs slowly; provide optimization suggestions for a MySQL environment:
SELECT * FROM logs WHERE DATE(create_time) = '2023-10-01';

Pagination optimization

I am using a MySQL database. Optimize the following pagination query to avoid deep‑offset issues:
SELECT * FROM products LIMIT 10000, 20;

Avoid full‑table scans

I am using a MySQL database. Check whether the following query may cause a full‑table scan and provide improvement advice:
SELECT username FROM users WHERE SUBSTRING(email, 1, 5) = 'admin';

3. Data Analysis Prompts

These prompts let you ask DeepSeek to produce analytical SQL for reporting and insight extraction.

Statistical metrics

I am using a MySQL database. Generate a SQL query that calculates, for each region in the user table, the average age, maximum age, and gender distribution percentages.

Time‑series trend

I am using a MySQL database. Generate a SQL query that counts weekly order volumes for the past three months and compares them with the same period in the previous year to compute growth rates.

Pivot / cross‑tabulation

I am using a MySQL database. Transform the sales data by month and product category using a CASE expression or PIVOT function. Source columns: sale_date, category, amount.

Outlier detection

I am using a MySQL database. Identify orders whose amount exceeds three standard deviations above the mean and return them as high‑value outliers.

User‑journey funnel

I am using a MySQL database. Analyze the conversion path from "view product" to "place order" and generate a funnel analysis SQL based on an event‑log table.

4. Database Management Prompts

Prompt templates for designing schemas, handling backups, managing permissions, and partitioning.

Table schema design

I am using a MySQL database. Design a user table that stores basic information, registration time, last login time, and includes appropriate index recommendations.

Backup and restore

I am using a MySQL database. Generate a command to back up the database and explain how to restore the data from the backup file.

Permission management

I am using a MySQL database. Create a role that can only read the "customer" table in a specific database and cannot modify any data.

Partitioned tables

I am using a MySQL database. For a log table, generate statements to partition the data by month (one partition per month) using MySQL or PostgreSQL syntax.

Data cleaning

I am using a MySQL database. Write a SQL statement that removes duplicate order records (same order_id) while keeping the most recent entry.

5. Debugging and Error‑Handling Prompts

These prompts assist in diagnosing syntax errors, deadlocks, isolation issues, and performance fluctuations.

Syntax error diagnosis

I am using a MySQL database. The following SQL raises "Unknown column" error. Please review and correct it: [Paste erroneous SQL here]

Deadlock analysis

I am using a MySQL database. Analyze the provided MySQL deadlock log, explain the cause, and suggest a resolution. [Paste log snippet here]

Transaction isolation problem

I am using a MySQL database. Simulate a "non‑repeatable read" scenario and generate test SQL using the READ COMMITTED isolation level.

Performance fluctuation investigation

I am using a MySQL database. A certain query usually runs fast but occasionally slows down. What could be the reasons and how can I monitor it with SQL?

6. Advanced Feature Prompts

Leverage window functions, recursive CTEs, JSON handling, and full‑text search.

Window function application

I am using MySQL 8.0. Generate a SQL query that ranks employees by salary within each department using ROW_NUMBER or RANK.

Recursive CTE query

I am using a MySQL database. Using a recursive CTE, retrieve all descendant nodes of a given node in a hierarchical employee table.

JSON data extraction

I am using a MySQL database. Extract the nested "phone_number" field from a JSON column (e.g., user_info).

Full‑text search

In PostgreSQL, create a full‑text index on the "description" column and optimize fuzzy searches.

These prompts constitute a ready‑to‑use toolbox for anyone working with SQL and DeepSeek, allowing quick generation, tuning, analysis, and troubleshooting of database queries.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqlDatabase OptimizationDeepSeek
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.