Main Site β†—

sql

by benchflow-ai890172GitHub

Sql standards for sql in Database environments. Covers best practices,

Unlock Deep Analysis

Use AI to visualize the workflow and generate a realistic output preview for this skill.

Powered by Fastest LLM

Development
Compatible Agents
Claude Code
Claude Code
~/.claude/skills/
Codex CLI
Codex CLI
~/.codex/skills/
Gemini CLI
Gemini CLI
~/.gemini/skills/
O
OpenCode
~/.opencode/skills/
O
OpenClaw
~/.openclaw/skills/
GitHub Copilot
GitHub Copilot
~/.copilot/skills/
Cursor
Cursor
~/.cursor/skills/
W
Windsurf
~/.codeium/windsurf/skills/
C
Cline
~/.cline/skills/
R
Roo Code
~/.roo/skills/
K
Kiro
~/.kiro/skills/
J
Junie
~/.junie/skills/
A
Augment Code
~/.augment/skills/
W
Warp
~/.warp/skills/
G
Goose
~/.config/goose/skills/
SKILL.md

SQL

Master relational databases from the command line. Covers SQLite, PostgreSQL, MySQL, and SQL Server with battle-tested patterns for schema design, querying, migrations, and operations.

When to Use

Working with relational databasesβ€”designing schemas, writing queries, building migrations, optimizing performance, or managing backups. Applies to SQLite, PostgreSQL, MySQL, and SQL Server.

Quick Reference

TopicFile
Query patternspatterns.md
Schema designschemas.md
Operationsoperations.md

Core Rules

1. Choose the Right Database

Use CaseDatabaseWhy
Local/embeddedSQLiteZero setup, single file
General productionPostgreSQLBest standards, JSONB, extensions
Legacy/hostingMySQLWide hosting support
Enterprise/.NETSQL ServerWindows integration

2. Always Parameterize Queries

# ❌ NEVER
cursor.execute(f"SELECT * FROM users WHERE id = {user_id}")

# βœ… ALWAYS
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))

3. Index Your Filters

Any column in WHERE, JOIN ON, or ORDER BY on large tables needs an index.

4. Use Transactions

BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;

5. Prefer EXISTS Over IN

-- βœ… Faster (stops at first match)
SELECT * FROM orders o WHERE EXISTS (
  SELECT 1 FROM users u WHERE u.id = o.user_id AND u.active
);

Quick Start

SQLite

sqlite3 mydb.sqlite                              # Create/open
sqlite3 mydb.sqlite "SELECT * FROM users;"       # Query
sqlite3 -header -csv mydb.sqlite "SELECT *..." > out.csv
sqlite3 mydb.sqlite "PRAGMA journal_mode=WAL;"   # Better concurrency

PostgreSQL

psql -h localhost -U myuser -d mydb              # Connect
psql -c "SELECT NOW();" mydb                     # Query
psql -f migration.sql mydb                       # Run file
\dt  \d+ users  \di+                             # List tables/indexes

MySQL

mysql -h localhost -u root -p mydb               # Connect
mysql -e "SELECT NOW();" mydb                    # Query

SQL Server

sqlcmd -S localhost -U myuser -d mydb            # Connect
sqlcmd -Q "SELECT GETDATE()"                     # Query
sqlcmd -S localhost -d mydb -E                   # Windows auth

Common Traps

NULL Traps

  • NOT IN (subquery) returns empty if subquery has NULL β†’ use NOT EXISTS
  • NULL = NULL is NULL, not true β†’ use IS NULL
  • COUNT(column) excludes NULLs, COUNT(*) counts all

Index Killers

  • Functions on columns β†’ WHERE YEAR(date) = 2024 scans full table
  • Type conversion β†’ WHERE varchar_col = 123 skips index
  • LIKE '%term' can't use index β†’ only LIKE 'term%' works
  • Composite (a, b) won't help filtering only on b

Join Traps

  • LEFT JOIN with WHERE on right table becomes INNER JOIN
  • Missing JOIN condition = Cartesian product
  • Multiple LEFT JOINs can multiply rows

EXPLAIN

-- PostgreSQL
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM orders WHERE user_id = 5;

-- SQLite
EXPLAIN QUERY PLAN SELECT * FROM orders WHERE user_id = 5;

Red flags:

  • Seq Scan on large tables β†’ needs index
  • Rows Removed by Filter high β†’ index doesn't cover filter
  • Actual vs estimated rows differ β†’ run ANALYZE tablename;

Index Strategy

-- Composite index (equality first, range last)
CREATE INDEX idx_orders ON orders(user_id, status);

-- Covering index (avoids table lookup)
CREATE INDEX idx_orders ON orders(user_id) INCLUDE (total);

-- Partial index (smaller, faster)
CREATE INDEX idx_pending ON orders(user_id) WHERE status = 'pending';

Portability

FeaturePostgreSQLMySQLSQLiteSQL Server
LIMITLIMIT nLIMIT nLIMIT nTOP n
UPSERTON CONFLICTON DUPLICATE KEYON CONFLICTMERGE
Booleantrue/false1/01/01/0
Concat||CONCAT()||+

Related Skills

Install with clawhub install <slug> if user confirms:

  • prisma β€” Node.js ORM
  • sqlite β€” SQLite-specific patterns
  • analytics β€” data analysis queries

Feedback

  • If useful: clawhub star sql
  • Stay updated: clawhub sync

Source: https://github.com/benchflow-ai/SkillsBench#registry-terminal_bench_1.0-pandas-sql-query-environment-skills-sql

Content curated from original sources, copyright belongs to authors

Grade B
-AI Score
Best Practices
Checking...
Try this Skill

User Rating

USER RATING

0UP
0DOWN
Loading files...

WORKS WITH

Claude Code
Claude
Codex CLI
Codex
Gemini CLI
Gemini
O
OpenCode
O
OpenClaw
GitHub Copilot
Copilot
Cursor
Cursor
W
Windsurf
C
Cline
R
Roo
K
Kiro
J
Junie
A
Augment
W
Warp
G
Goose