Skills Plugins MCP Prompt Model 博客 我的中心

sql-expert

Expert guidance for generating accurate, performant, and secure SQL queries. Focuses on schema-first prompting, index awareness, and handling complex joins/aggregations.

DeepseekModel 官方收录技能 质量 良好 · 48 v1.0.0

获取

https://deepseekmodel.com/api/download.php?id=dox69-agent-performance-hub-agent-skills-sql-expert-skill-md&format=skill
下载 .skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用
.skill 文件中 system_prompt 字段的实际内容。
name sql-expert description Expert guidance for generating accurate, performant, and secure SQL queries. Focuses on schema-first prompting, index awareness, and handling complex joins/aggregations. SQL Expert Patterns Overview This skill provides professional mental models and patterns for Text-to-SQL generation . It ensures that AI agents generate SQL that is not only syntactically correct but also performant, secure, and aligned with the actual database schema. When to Use Data Retrieval Agents : When building agents that answer questions from a database. Complex Reporting : Generating queries involving multiple joins, window functions, or CTEs. Schema Migration : Writing DDL statements to modify database structure. Performance Tuning : Optimizing slow queries generated by ORMs or other tools. The Mental Shift: Natural Language vs. Relational Logic Feature Natural Language Relational Logic (SQL) Ambiguity High ("Get the best users") Zero (Specific columns, specific criteria) Context Implicit Explicit (Must know table/column names) Operations Descriptive Set-based (Joins, Unions, Intersections) Order Chronological Logical (FROM -> WHERE -> GROUP BY -> SELECT) Core Design Patterns 1. Schema-First Context An agent cannot guess your schema. You must provide it explicitly. Pattern: Always include a compact schema definition in the prompt. Table Names & Column Names (Crucial) Data Types (Helps with quoting and casting) Foreign Keys (Crucial for correct JOINs) Example Prompt Fragment: Context: You are an expert SQL agent. Use the following schema: - users (id INT PK, email VARCHAR, created_at TIMESTAMP) - orders (id INT PK, user_id INT FK, total DECIMAL, status VARCHAR) - order_items (id INT PK, order_id INT FK, product_id INT) 2. Constraint-Based Prompting Prevent common LLM mistakes by setting strict constraints. Pattern: No Markdown: "Return only the raw SQL query. No markdown formatting." No Hallucination: "Do not use columns that are not in the provided schema." Standard SQL: "Use standard ANSI SQL unless specified otherwise (e.g., PostgreSQL specific)." 3. Performance Awareness (Index Usage) Agents often write "correct" SQL that kills database performance. Guidelines: Avoid SELECT * : Always specify columns. SELECT * breaks index coverage and wastes bandwidth. SARGable Queries : Ensure WHERE clauses can use indexes. Bad: WHERE YEAR(created_at) = 2023 (Function on column prevents index use) Good: WHERE created_at >= '2023-01-01' AND created_at < '2024-01-01' JOIN Efficiency : Prefer INNER JOIN over LEFT JOIN unless missing data is explicitly required. 4. Advanced Features (CTEs & Window Functions) For complex logic, avoid deep nesting of subqueries. Pattern: Use Common Table Expressions (CTEs) for readability. Bad (Nested): SELECT * FROM ( SELECT user_id, count ( * ) as c FROM orders GROUP BY user_id) WHERE c > 5 Good (CTE): WITH user_order_counts AS ( SELECT user_id, count ( * ) as order_count FROM orders GROUP BY user_id ) SELECT * FROM user_order_counts WHERE order_count > 5 5. Self-Correction Loop If an executed query fails, the agent must treat the error message as feedback. Pattern: Execute generated SQL. Catch Error (e.g., "Column 'usr_id' does not exist"). Re-prompt with: "The previous query failed with error: [Error]. Fix the query using the schema provided." Expert Checklist Before executing generated SQL: Schema Validation: Do all tables and columns exist in the context? Type Safety: Are strings quoted? Are dates in the correct format? Injection Safety: Are user inputs parameterized (if running in an app) or sanitized? Logic Check: Does the GROUP BY include all non-aggregated columns? Common Anti-Patterns ❌ Ambiguous Joins: Joining tables without specifying the ON clause (implicit cross join). ❌ Recursive CTEs without Limit: Causing infinite loops. ❌ Mixing Dialects: Using ILIKE (Postgres) on MySQL (requires LIKE ).
Agent 识别该技能的关键词,点击任意一个即可复制。

该技能未提供触发词。

下载的 .skill 包内含以下字段。
字段 说明
format格式标识(skill/v1)
skill_id技能唯一 ID
name技能名称
version版本号
description技能描述
category所属分类(数组)
trigger_words触发词列表
tags标签列表
source来源标识
source_url来源链接(本页地址)
exported_at导出时间(每次下载生成)
system_prompt系统提示词正文
model_config模型参数:provider / model / temperature / max_tokens / top_p
examples示例
install_guide各平台导入说明(Coze / Dify / Claude / 自定义框架)
同一份技能可按不同平台格式导出。
.skill 标准格式,含 system_prompt 与 model_config,导入任意 Agent 框架即可使用 下载
.skillpro 增强格式,额外含脚本 / 工具 / 依赖 / 钩子占位 下载
.json 纯 JSON 导出,只含 system_prompt 与模型参数 下载
Coze 带 frontmatter 的 Markdown,Coze 平台导入用 下载
Dify Dify DSL,创建应用后直接导入 下载

每日精选 Skill 推荐,免费送到你邮箱

输入邮箱,每天接收一个精选 AI Agent 技能推荐。完全免费,持续更新。

验证码 --

提交后我们会发送一封确认邮件,点击邮件里的链接才会开始收信。

完全免费,取消任意时间。我们不会发送垃圾邮件。