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 ).
このスキルを起動するキーワード。クリックでコピーできます。

このスキルにはトリガーワードがありません。

ダウンロードした .skill に含まれるフィールド。
フィールド 説明
formatフォーマット識別子(skill/v1)
skill_idスキル固有 ID
nameスキル名
versionバージョン
description説明
categoryカテゴリ(配列)
trigger_wordsトリガーワード
tagsタグ
sourceソース
source_urlソース 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 拡張形式。scripts / tools / dependencies / hooks を含む ダウンロード
.json 純粋な JSON 出力。system_prompt とモデル設定のみ ダウンロード
Coze frontmatter 付き Markdown。Coze へのインポート用 ダウンロード
Dify Dify DSL。アプリ作成後にそのままインポート ダウンロード

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

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

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

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