Agent skill

SQL Tutor

by rongxinzy in rongxinzy/RongxinAI

帮助用户编写和优化 SQL 查询,包括将自然语言转换为 SQL、提供查询优化建议以及解读 EXPLAIN 执行计划。当用户需要 SQL 相关帮助时触发,例如直接请求“自然语言转SQL”、“帮我优化这条SQL”、“解释一下这个执行计划”,或提及关键词如 NL2SQL、SQL优化、慢查询、索引建议、全表扫描、SQL调优,以及支持 SQLite 和 PostgreSQL 数据库时。

MITAuto-check passedDatabases

Install SQL Tutor

skills CLI
$ npx skills add rongxinzy/RongxinAI --skill sql-tutor -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rongxinzy/RongxinAI sql-tutor --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rongxinzy/RongxinAI.git skills-src && mkdir -p .claude/skills && cp -r skills-src/SKILLs/sql-tutor .claude/skills/sql-tutor && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
sql-tutor
GitHub stars
154
Token cost
~1.4k tokens
SKILL.md length
267 words
Files
6 (incl. scripts)
Skills in repo
100
Repo updated
First seen
Licence
MIT

At a glance

帮助用户编写和优化 SQL 查询,包括将自然语言转换为 SQL、提供查询优化建议以及解读 EXPLAIN 执行计划。当用户需要 SQL 相关帮助时触发,例如直接请求“自然语言转SQL”、“帮我优化这条SQL”、“解释一下这个执行计划”,或提及关键词如 NL2SQL、SQL优化、慢查询、索引建议、全表扫描、SQL调优,以及支持 SQLite 和 PostgreSQL 数据库时。

  • Works in 4 steps: 使用 schema 命令提取数据库表结构 → 将 Schema 作为上下文,将用户的自然语言需求翻译为 SQL → 使用 optimize 命令检查生成的 SQL 是否有优化空间 → …
  • Tasks that involve SQL
  • SKILL.md covers 能力概览, 工作流程, Quick Start and 详细用法, plus 5 more sections
  • Runs Python scripts from its folder; calls python3 and pip

What it does

SQL Tutor is an agent skill from rongxinzy/RongxinAI. 帮助用户编写和优化 SQL 查询,包括将自然语言转换为 SQL、提供查询优化建议以及解读 EXPLAIN 执行计划。当用户需要 SQL 相关帮助时触发,例如直接请求“自然语言转SQL”、“帮我优化这条SQL”、“解释一下这个执行计划”,或提及关键词如 NL2SQL、SQL优化、慢查询、索引建议、全表扫描、SQL调优,以及支持 SQLite 和 PostgreSQL 数据库时。

Its SKILL.md is about 1.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 7 other files, including scripts (for example `scripts/sql_query_helper.py` and `zhiyuan/metadata.yaml`).

It sits in Databases, covering SQL. It works with SQL, SQLite and PostgreSQL. The repository describes itself as: An all-in-one local AI Agent workspace with a fully self-developed stack. The licence is MIT.

When your agent uses it

  • Tasks that involve SQL

Example prompts

  • “自然语言转SQL”
  • “帮我优化这条SQL”
  • “解释一下这个执行计划”
  • “/sql-tutor”

Requirements

  • Python 3

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. 使用 schema 命令提取数据库表结构
  2. 将 Schema 作为上下文,将用户的自然语言需求翻译为 SQL
  3. 使用 optimize 命令检查生成的 SQL 是否有优化空间
  4. 使用 explain 命令验证查询执行计划

What it can do on your machine

Read from SKILL.md and the folder at commit 901b46b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • python3
    • pip

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pip, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

SQL Tutor loads about 1.4k tokens when it runs. Until then it costs about 50 tokens; SKILL.md has 267 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~50
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from rongxinzy/RongxinAI at commit 901b46b, republished under its MIT licence (© rongxinzy). 267 words, ~1,437 tokens.

Download SKILL.mdSave it as .claude/skills/sql-tutor/SKILL.md (or your agent's skills folder). This skill also uses 5 other files; get the full folder from GitHub.
name
sql-tutor
description
帮助用户编写和优化 SQL 查询,包括将自然语言转换为 SQL、提供查询优化建议以及解读 EXPLAIN 执行计划。当用户需要 SQL 相关帮助时触发,例如直接请求“自然语言转SQL”、“帮我优化这条SQL”、“解释一下这个执行计划”,或提及关键词如 NL2SQL、SQL优化、慢查询、索引建议、全表扫描、SQL调优,以及支持 SQLite 和 PostgreSQL 数据库时。
license
MIT

sql-query-helper

SQL 查询辅助工具 —— 自然语言→SQL 翻译、查询优化分析、EXPLAIN 执行计划解读。

能力概览

功能说明
Schema 提取提取数据库表结构(列、类型、索引、外键、样本数据),为 NL→SQL 提供上下文
自然语言→SQL结合 Schema 上下文,将自然语言描述翻译为 SQL 查询
查询优化分析基于 13 条规则检测 SQL 反模式,给出优化建议
EXPLAIN 解读执行 EXPLAIN 并解读查询计划,识别全表扫描、索引缺失等问题

工作流程

自然语言→SQL
  1. 使用 schema 命令提取数据库表结构
  2. 将 Schema 作为上下文,将用户的自然语言需求翻译为 SQL
  3. 使用 optimize 命令检查生成的 SQL 是否有优化空间
  4. 使用 explain 命令验证查询执行计划
bash
# 步骤1:提取 Schema(紧凑模式,适合作为 LLM 上下文)
python3 scripts/sql_query_helper.py --db-path data.db schema --compact

# 步骤2:分析 SQL 优化建议
python3 scripts/sql_query_helper.py optimize "SELECT * FROM orders WHERE user_id = 100"

# 步骤3:查看 EXPLAIN 执行计划
python3 scripts/sql_query_helper.py --db-path data.db explain "SELECT * FROM orders WHERE user_id = 100"

Quick Start

Schema 提取
bash
# 提取完整 Schema(JSON 格式,含样本数据)
python3 scripts/sql_query_helper.py --db-path data.db schema

# 紧凑模式(纯文本,适合嵌入 prompt)
python3 scripts/sql_query_helper.py --db-path data.db schema --compact

# 不采样数据
python3 scripts/sql_query_helper.py --db-path data.db schema --sample-rows 0

# PostgreSQL
python3 scripts/sql_query_helper.py --db-type postgres --dsn "host=localhost dbname=mydb user=reader" schema --compact
查询优化分析
bash
# 分析 SQL 查询(无需数据库连接,纯规则检测)
python3 scripts/sql_query_helper.py optimize "SELECT * FROM orders o, users u WHERE o.user_id = u.id"

python3 scripts/sql_query_helper.py optimize "SELECT name FROM users WHERE UPPER(email) LIKE '%@GMAIL.COM'"

python3 scripts/sql_query_helper.py optimize "SELECT id, (SELECT COUNT(*) FROM orders WHERE user_id = u.id) AS order_count FROM users u"
EXPLAIN 解读
bash
# SQLite EXPLAIN
python3 scripts/sql_query_helper.py --db-path data.db explain "SELECT * FROM orders WHERE user_id = 100"

# PostgreSQL EXPLAIN
python3 scripts/sql_query_helper.py --db-type postgres --dsn "host=localhost dbname=mydb" explain "SELECT * FROM orders WHERE user_id = 100"

# PostgreSQL EXPLAIN ANALYZE(实际执行查询,获取真实数据)
python3 scripts/sql_query_helper.py --db-type postgres --dsn "host=localhost dbname=mydb" explain --analyze "SELECT * FROM orders WHERE user_id = 100"

详细用法

全局参数
参数必填默认值说明
--db-type否sqlite数据库类型:sqlite 或 postgres
--db-pathschema/explain 时(SQLite)—SQLite 数据库文件路径
--dsnschema/explain 时(PostgreSQL)—PostgreSQL 连接串
子命令
命令需要数据库说明
schema是提取数据库表结构
optimize <sql>否SQL 查询优化分析(纯规则检测)
explain <sql>是执行 EXPLAIN 并解读
schema 参数
参数默认值说明
--sample-rows, -n3每表采样行数(0 表示不采样)
--compactfalse紧凑文本输出(适合嵌入 prompt)
explain 参数
参数默认值说明
--analyzefalse使用 EXPLAIN ANALYZE(仅 PostgreSQL,会实际执行查询)

优化规则清单

optimize 命令检测以下 13 类 SQL 反模式:

规则严重度说明
avoid-select-starwarning避免 SELECT *,显式列出列名
unbounded-queryinfo缺少 WHERE 和 LIMIT
leading-wildcard-likewarningLIKE '%...' 导致索引失效
or-conditioninfoOR 条件可能阻止索引使用
not-in-subquerywarningNOT IN (子查询) 性能差
scalar-subquerywarningSELECT 中的标量子查询逐行执行
function-on-columnwarningWHERE 中对列使用函数导致索引失效
implicit-joininfo隐式连接可读性差
distinct-usageinfoDISTINCT 可能掩盖 JOIN 问题
order-without-limitinfoORDER BY 没有 LIMIT
deep-nestingwarning多层嵌套子查询
having-without-groupwarningHAVING 没有 GROUP BY
not-equal-filterinfo!= 条件无法有效使用索引

EXPLAIN 解读项

检测项适用数据库说明
全表扫描SQLite / PostgreSQL检测 Seq Scan / SCAN TABLE
自动临时索引SQLiteSQLite 自动创建临时索引,说明缺少永久索引
覆盖索引SQLite / PostgreSQL索引包含所有查询列,无需回表
磁盘排序PostgreSQL排序溢出到磁盘
嵌套循环连接PostgreSQL大表嵌套循环性能差
行数估计偏差PostgreSQL (ANALYZE)预估行数与实际行数差距大于 10 倍

输出示例

schema --compact
-- Database: sqlite
-- users (1500 rows): id INTEGER  PK, name TEXT, email TEXT, age INTEGER, created_at TEXT
--   IDX(unique): idx_users_email on (email)
-- orders (8200 rows): id INTEGER  PK, user_id INTEGER, amount REAL, status TEXT, created_at TEXT
--   FK: user_id -> users.id
--   IDX: idx_orders_user_id on (user_id)
optimize
json
{
  "sql": "SELECT * FROM orders o, users u WHERE o.user_id = u.id",
  "issues": [
    {
      "severity": "warning",
      "rule": "avoid-select-star",
      "message": "避免 SELECT *:只选择需要的列,减少 I/O 和网络传输",
      "suggestion": "将 SELECT * 改为显式列出需要的列名"
    },
    {
      "severity": "info",
      "rule": "implicit-join",
      "message": "使用了隐式连接(逗号分隔表),可读性差且易出错",
      "suggestion": "改用显式 JOIN ... ON 语法,提高可读性和可维护性"
    }
  ]
}
explain (SQLite)
json
{
  "db_type": "sqlite",
  "query": "SELECT * FROM orders WHERE user_id = 100",
  "plan": [
    {"id": 2, "parent": 0, "detail": "SEARCH orders USING INDEX idx_orders_user_id (user_id=?)"}
  ],
  "interpretation": [
    {
      "severity": "ok",
      "type": "index-search",
      "detail": "使用索引查找: idx_orders_user_id",
      "suggestion": "索引查找效率良好"
    }
  ]
}

安全机制

  • 只读连接:SQLite 使用 ?mode=ro;PostgreSQL 使用 SET SESSION READ ONLY
  • SQL 白名单:仅允许 SELECT / WITH / EXPLAIN 开头
  • 危险关键字拦截:INSERT、UPDATE、DELETE、DROP 等 30+ 关键字被阻止
  • 多语句拦截:禁止分号分隔的多条 SQL
  • 标识符转义:表名使用双引号转义,防止 SQL 注入

依赖

  • Python 3.8+(sqlite3 为内置模块)
  • PostgreSQL 支持需安装:pip install psycopg2-binary
  • optimize 命令无需数据库连接,零外部依赖

© rongxinzy, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 5 other files (scripts) in SKILLs/sql-tutor of rongxinzy/RongxinAI.

  • SKILL.md
  • LICENSE
  • requirements.txt
  • scripts/sql_query_helper.py
  • zhiyuan/icon.png
  • zhiyuan/metadata.yaml

Open the folder on GitHubat commit 901b46b

Compare with similar skills

SQL Tutor next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

SQL Tutor compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
SQL Tutor this skillrongxinzy/RongxinAI154—~1.4kAutomated safety check: PassMIT
SQL Database Support for pRESTprest/prest4.6k—~1.6kAutomated safety check: PassMIT
Squixeduardofuncao/squix273—~784Automated safety check: PassMIT
Golang Databaseunxed/f42402 repos~2.9kAutomated safety check: PassMIT
Database MigrationRain-kl/OpenFlare288—~1.3kAutomated safety check: PassApache-2.0
DB Migratealexeykrol/claude-code-starter194—~405Automated safety check: NotesNone

Similar skills

  • Guides classifying, gap-analyzing and scaffolding support for a new SQL database in pREST, from Postgres-compatible variants to entirely new dialects.

    4.6k GitHub stars~1.6k tokensUpdated yesterday
    DatabasesAuto-check passed
  • Squix

    eduardofuncao/squix

    Run SQL queries across databases (Postgres, MySQL, SQLite, etc.) via the squix CLI.

    273 GitHub stars~784 tokensUpdated 15 days ago
    DatabasesAuto-check passed
  • Comprehensive guide for Go database access — parameterized queries, struct scanning, NULLable columns, transactions, isolation levels, SELECT FOR UPDATE, connection pool, batch processing, context…

    240 GitHub starsUsed in 2 repos~2.9k tokens
    DatabasesAuto-check passed
  • Database Migration

    Rain-kl/OpenFlare

    Wavelet 项目专用:当新增或修改数据库表结构、索引、初始化数据、系统配置 seed、模板 seed、默认管理员、goose SQL 迁移、internal/infra/persistence/migrator、ClickHouse 分析库 DDL 或数据库升级流程时必须使用。本技能指导在 internal/infra/persistence/migrator/goose 下编写…

    288 GitHub stars~1.3k tokensUpdated today
    DatabasesAuto-check passed
  • DB Migrate

    alexeykrol/claude-code-starter

    Миграция схемы базы данных: SQLite → PostgreSQL/Supabase. An agent skill from alexeykrol/claude-code-starter.

    194 GitHub stars~405 tokensUpdated 2 mo ago
    DatabasesAuto-check: notes
  • Database Marchat

    Cod-e-Codes/marchat

    Changes marchat SQL schema and queries across SQLite, PostgreSQL, and MySQL using dialect helpers.

    137 GitHub stars~985 tokensUpdated 4 days ago
    DatabasesAuto-check passed

More from rongxinzy/RongxinAI

All 100 skills in this repo
  • SaaS Metrics Coach

    rongxinzy/RongxinAI

    SaaS financial health advisor. An agent skill from rongxinzy/RongxinAI.

    154 GitHub starsUsed in 2 repos~1.3k tokens
    Auto-check passed
  • Churn Prevention

    rongxinzy/RongxinAI

    Reduce voluntary and involuntary churn through cancel flow design, save offers, exit surveys, and dunning sequences.

    154 GitHub starsUsed in 3 repos~2.6k tokens
    Auto-check passed
  • Presentation Studio

    rongxinzy/RongxinAI

    The only skill for creating a new PowerPoint deck. An agent skill from rongxinzy/RongxinAI.

    154 GitHub stars~2.1k tokensUpdated today
    Auto-check passed
  • Zhiyuan Expert Manager

    rongxinzy/RongxinAI

    ZhiYuan Agent expert package lifecycle manager for the pi engine.

    154 GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • Ziwei Doushu

    rongxinzy/RongxinAI

    Professional Ziwei Doushu consultation skill with an offline calculation engine.

    154 GitHub stars~746 tokensUpdated today
    Auto-check passed
  • Lark Mail

    rongxinzy/RongxinAI

    飞书邮箱:Use when user mentions 起草邮件、写邮件、草稿、发送/回复/转发邮件、查阅邮件、看邮件、搜索邮件、邮件文件夹、邮件标签、邮件联系人、监听新邮件、邮件收信规则等;use for mail/email intent only.

    154 GitHub starsUsed in 3 repos~4.1k tokens
    Auto-check: warnings

Categories

Questions about SQL Tutor

What does SQL Tutor do?

帮助用户编写和优化 SQL 查询,包括将自然语言转换为 SQL、提供查询优化建议以及解读 EXPLAIN 执行计划。当用户需要 SQL 相关帮助时触发,例如直接请求“自然语言转SQL”、“帮我优化这条SQL”、“解释一下这个执行计划”,或提及关键词如 NL2SQL、SQL优化、慢查询、索引建议、全表扫描、SQL调优,以及支持 SQLite 和 PostgreSQL 数据库时。. SQL Tutor is an agent skill from rongxinzy/RongxinAI.

When should I use SQL Tutor?

SQL Tutor fits situations like: tasks that involve SQL.

How do I install SQL Tutor in Claude Code?

Run `npx skills add rongxinzy/RongxinAI --skill sql-tutor -a claude-code`. Or copy the skill folder (SKILLs/sql-tutor in rongxinzy/RongxinAI) into .claude/skills/sql-tutor in your project. Claude Code loads it when a task matches its description.

How do I install SQL Tutor in Codex?

Run `npx skills add rongxinzy/RongxinAI --skill sql-tutor -a codex`. Or copy the skill folder (SKILLs/sql-tutor in rongxinzy/RongxinAI) into .agents/skills/sql-tutor in your project. Codex loads it when a task matches its description.

Can I use SQL Tutor in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rongxinzy/RongxinAI --skill sql-tutor -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/sql-tutor, .gemini/skills/sql-tutor, .github/skills/sql-tutor and .opencode/skills/sql-tutor in your project.

What does SQL Tutor need to run?

Going by SKILL.md and its folder, SQL Tutor needs Python for the scripts in its folder and the command-line tools its instructions call (python3 and pip). Our summary lists: Python 3.

Does SQL Tutor access the network?

SKILL.md contains no URLs. Its commands use pip, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is SQL Tutor safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does SQL Tutor use?

SQL Tutor is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does SQL Tutor use?

About 1.4k tokens (SKILL.md is roughly 5.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to SQL Tutor?

Skills that share tags, products or a category with SQL Tutor: SQL Database Support for pREST (prest/prest, 4.6k stars), Squix (eduardofuncao/squix, 273 stars), Golang Database (unxed/f4, 240 stars) and Database Migration (Rain-kl/OpenFlare, 288 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains SQL Tutor?

rongxinzy (a GitHub organization) maintains it in rongxinzy/RongxinAI, which has 154 GitHub stars. The repository holds 100 skills in this directory. The repository was last updated on October 7, 2026.

Source: rongxinzy/RongxinAI on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.