Token导航 LogoToken导航

Agent Skill · 开发规范

sql-best-practices(SQL 最佳实践)

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

sql-best-practices 是开发规范类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为只读;许可证为 MIT,第三方扫描已通过,按安装量在开发规范类的 1,265 个 Skill 里排第 234。

总安装 6,144周安装 251GitHub Stars 87下载 1,988核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:sql-best-practices(SQL 最佳实践)
来源仓库:https://github.com/mindrally/skills
仓库路径:skills/sql-best-practices
安装命令:
npx skills add https://github.com/mindrally/skills --skill sql-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/mindrally/skills --skill sql-best-practices

这个 Skill 是做什么的

开发规范类 Skill 用来统一代码风格、目录结构和评审口径,产出多为检查清单或改写建议。

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更。涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

安装前建议核对仓库维护状态及是否会触发联网、命令执行或文件读写。

来源仓库内路径:skills/sql-best-practices

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/mindrally/skills --skill sql-best-practices;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它标注为只读,先用只读任务试一次,确认行为符合预期再扩大使用范围。

常见问题

6 条

sql-best-practices 怎么安装?

在终端执行 npx skills add https://github.com/mindrally/skills --skill sql-best-practices。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

sql-best-practices 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

sql-best-practices 需要什么权限?

权限级别是只读。该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

sql-best-practices 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

sql-best-practices 用的人多吗?

公开数据是累计安装 6,144 次,近一周安装 251 次,下载 1,988 次,GitHub 87 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

sql-best-practices 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发规范类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 需要厂商级技术支持和 SLA 的生产系统。

开发规范类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
vercel-react-best-practices

Vercel React 最佳实践 · Codex、Claude

8,490,72025,918操作浏览器MIT通过
web-design-guidelines

网页设计指南 · Codex、Claude

6,686,01625,885需要联网MIT有提醒
remotion-best-practices

Remotion 最佳实践 · Codex、Claude

6,505,6323,027操作浏览器MIT有提醒
supabase-postgres-best-practices

Supabase Postgres 最佳实践 · Codex、Claude

3,175,5232,030需要联网MIT通过
next-best-practices

Next.js 最佳实践 · Codex、Claude

1,848,240841操作浏览器MIT通过
sql-best-practices

SQL 最佳实践 · 本页

6,14487只读MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

SQL Best Practices

Core Principles

  • Write clear, readable SQL with consistent formatting and meaningful aliases
  • Prioritize query performance through proper indexing and optimization
  • Implement security best practices to prevent SQL injection
  • Use transactions appropriately for data integrity
  • Document complex queries with inline comments

Query Writing Standards

Formatting and Style

  • Use uppercase for SQL keywords (SELECT, FROM, WHERE, JOIN)
  • Place each major clause on a new line for readability
  • Use meaningful table aliases (e.g., customers AS c not customers AS x)
  • Indent subqueries and nested conditions consistently
  • Align column lists and conditions for visual clarity
SELECT
    c.customer_id,
    c.customer_name,
    o.order_date,
    o.total_amount
FROM customers AS c
INNER JOIN orders AS o ON c.customer_id = o.customer_id
WHERE o.order_date >= '2024-01-01'
    AND o.status = 'completed'
ORDER BY o.order_date DESC;

Column Selection

  • Avoid SELECT * in production code; explicitly list required columns
  • Use column aliases to clarify output: SELECT first_name AS "First Name"
  • Consider the order of columns in SELECT for logical grouping

Filtering and Conditions

  • Place most restrictive conditions first in WHERE clauses
  • Use appropriate operators: prefer IN over multiple OR conditions
  • Use EXISTS instead of IN for subqueries when checking existence
  • Avoid functions on indexed columns in WHERE clauses when possible
  • Use parameterized queries to prevent SQL injection
-- Preferred: Use EXISTS for existence checks
SELECT c.customer_name
FROM customers AS c
WHERE EXISTS (
    SELECT 1 FROM orders AS o
    WHERE o.customer_id = c.customer_id
    AND o.order_date > '2024-01-01'
);

-- Avoid: Function on indexed column
WHERE YEAR(order_date) = 2024

-- Preferred: Range comparison
WHERE order_date >= '2024-01-01' AND order_date < '2025-01-01'

Join Best Practices

  • Always use explicit JOIN syntax instead of implicit joins in WHERE
  • Specify join type explicitly (INNER, LEFT, RIGHT, FULL OUTER)
  • Order joins from largest to smallest table when possible
  • Use appropriate join types based on data requirements
  • Be cautious with CROSS JOINs; ensure they are intentional
-- Explicit join (preferred)
SELECT c.name, o.order_id
FROM customers AS c
INNER JOIN orders AS o ON c.customer_id = o.customer_id;

-- Avoid implicit join
SELECT c.name, o.order_id
FROM customers c, orders o
WHERE c.customer_id = o.customer_id;

Performance Optimization

Indexing Guidelines

  • Create indexes on columns used in WHERE, JOIN, and ORDER BY clauses
  • Consider composite indexes for multi-column queries
  • Avoid over-indexing; each index adds write overhead
  • Regularly analyze and maintain indexes
  • Use covering indexes for frequently executed queries

Query Optimization

  • Use EXPLAIN/EXPLAIN ANALYZE to understand query execution plans
  • Limit result sets with TOP/LIMIT when full results are not needed
  • Use pagination for large result sets
  • Avoid correlated subqueries when possible; use JOINs instead
  • Consider query caching for frequently executed queries
-- Pagination example
SELECT product_id, product_name, price
FROM products
ORDER BY product_id
LIMIT 20 OFFSET 40;

Aggregation Best Practices

  • Filter before grouping when possible (WHERE vs HAVING)
  • Use appropriate aggregate functions (COUNT, SUM, AVG, etc.)
  • Consider window functions for running totals and rankings
-- Efficient: Filter before aggregation
SELECT category_id, COUNT(*) AS product_count
FROM products
WHERE active = true
GROUP BY category_id
HAVING COUNT(*) > 10;

Transaction Management

  • Keep transactions as short as possible
  • Use appropriate isolation levels for your use case
  • Always include error handling with ROLLBACK
  • Avoid user interaction during open transactions
  • Use savepoints for complex multi-step operations
BEGIN TRANSACTION;

UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;
UPDATE accounts SET balance = balance + 100 WHERE account_id = 2;

IF @@ERROR <> 0
    ROLLBACK TRANSACTION;
ELSE
    COMMIT TRANSACTION;

Security Best Practices

  • Always use parameterized queries or prepared statements
  • Never concatenate user input directly into SQL strings
  • Apply principle of least privilege for database users
  • Audit and log sensitive data access
  • Encrypt sensitive data at rest and in transit
-- Use parameterized queries (pseudo-code)
PREPARE stmt FROM 'SELECT * FROM users WHERE username = ?';
EXECUTE stmt USING @username;

Data Modification Best Practices

INSERT Operations

  • Always specify column names explicitly
  • Use bulk inserts for multiple rows when possible
  • Consider using MERGE/UPSERT for insert-or-update scenarios
INSERT INTO customers (customer_name, email, created_at)
VALUES
    ('John Doe', 'john@example.com', CURRENT_TIMESTAMP),
    ('Jane Smith', 'jane@example.com', CURRENT_TIMESTAMP);

UPDATE Operations

  • Always include a WHERE clause (unless intentionally updating all rows)
  • Test UPDATE queries with SELECT first
  • Consider using transactions for critical updates

DELETE Operations

  • Always include a WHERE clause
  • Use soft deletes (status flags) for recoverable data
  • Consider CASCADE effects on related tables

Naming Conventions

  • Use snake_case for table and column names
  • Use singular nouns for table names (customer, not customers)
  • Prefix primary keys with table name: customer_id
  • Use descriptive names: order_total not ot
  • Prefix boolean columns appropriately: is_active, has_shipped

Documentation

  • Comment complex business logic within queries
  • Document stored procedures with purpose, parameters, and examples
  • Maintain a data dictionary for table and column descriptions
  • Version control database schema changes

Error Handling

  • Implement proper error handling in stored procedures
  • Log errors with sufficient context for debugging
  • Return meaningful error messages to calling applications
  • Use TRY-CATCH blocks where supported

平台分布

OpenCode

25.57%
按下载量换算508

Claude Code

24.33%
按下载量换算484

Antigravity

18.57%
按下载量换算369

Codex

13.19%
按下载量换算262

Gemini CLI

8.46%
按下载量换算168

github-copilot

3.48%
按下载量换算69

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills