編寫複雜的 SQL 查詢和優化資料庫效能需要深入了解查詢模式、索引策略和資料庫特定語法。此技能提供專家指導,幫助建立高效能查詢、設計正規化結構,以及疑難排解 PostgreSQL、MySQL、SQLite 和 SQL Server 的效能問題。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“sql-expert”。 Write a query to find the top 5 customers by order total with their last order date
预期结果:
- Query uses a CTE to aggregate order totals per customer
- Uses ROW_NUMBER() window function for ranking
- Includes proper JOIN between customers and orders tables
- Filters to top 5 with ORDER BY and LIMIT
正在使用“sql-expert”。 Design a schema for a library management system with books, authors, and borrowers
预期结果:
- Creates books table with ISBN, title, and publication year
- Creates authors table with name and biography
- Creates junction table for book-author relationships
- Adds foreign key constraints for data integrity
正在使用“sql-expert”。 Explain why this query is slow and how to fix it
预期结果:
- Query performs full table scan on large table
- Missing index on filtered column causes performance issue
- Suggest creating index on status and created_at columns
- Recommend using LIMIT for exploratory queries
安全审计
低风险This is a legitimate educational SQL skill containing SQL documentation, patterns, and a Python helper utility using SQLAlchemy ORM with parameterized queries. All static findings are false positives caused by the scanner incorrectly flagging SQL keywords as cryptographic algorithms and system reconnaissance patterns. No malicious code or behaviors detected. Behavior matches stated purpose.
风险因素
⚡ 包含脚本 (1)
📁 文件系统访问 (1)
质量评分
你能构建什么
查詢參考
快速找到正確的 SQL 語法,用於連接、聚合和複雜查詢
效能調優
使用 EXPLAIN 計劃、索引建議和查詢模式優化慢速查詢
結構和遷移
設計正規化結構並建立安全、零停機時間的遷移腳本
试试这些提示
Write a SQL query to select [columns] from [table] where [condition] and order by [column] limit [number]
Write a query using window functions to calculate [ranking/running total/percentile] partitioned by [column] ordered by [column]
Design SQL tables for [use case] following third normal form with proper foreign keys and constraints
Analyze this query for performance issues and suggest optimizations using indexes and query restructuring: [paste query]
最佳实践
- 始終使用參數化查詢以防止 SQL 注入攻擊
- 為外鍵欄位和經常篩選的欄位建立索引以獲得更好的效能
- 對相關操作使用交易以確保原子性
避免
- 避免使用 SELECT * - 只指定需要的欄位以減少資料傳輸
- 不要在 WHERE 子句中的索引欄位上使用函數
- 切勿將使用者輸入直接串接到 SQL 查詢字串中