一键导入
sql
Write SQL queries, optimize database performance, design schemas, and debug SQL issues. Use for database operations, query optimization, and schema design.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Write SQL queries, optimize database performance, design schemas, and debug SQL issues. Use for database operations, query optimization, and schema design.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Work with Excel spreadsheets (XLSX/XLS/CSV) - read data, create spreadsheets, convert formats, analyze data, and generate reports. Use when the user asks to work with Excel files or spreadsheet data.
Generate unit tests, integration tests, and test data. Use when writing tests, improving test coverage, or creating test scenarios.
Refactor code to improve quality, apply SOLID principles, remove code smells, and suggest better patterns. Use when improving code structure or modernizing legacy code.
Work with PowerPoint presentations (PPTX/PPT) - read slides, extract content, create presentations, convert formats, and generate slide decks. Use when the user asks to work with PowerPoint files or presentations.
Work with PDF files - read, extract text/images/tables, create PDFs, merge, split, and convert PDFs. Use when the user asks to read, create, modify, or analyze PDF documents.
Parse, validate, transform, and manipulate JSON data. Use for JSON operations, schema validation, and data transformation.
| name | sql |
| description | Write SQL queries, optimize database performance, design schemas, and debug SQL issues. Use for database operations, query optimization, and schema design. |
| allowed-tools | Read, Bash |
Comprehensive SQL assistance for database operations.
Basic Queries:
-- SELECT with WHERE
SELECT name, email FROM users WHERE active = true;
-- JOIN operations
SELECT u.name, o.total
FROM users u
INNER JOIN orders o ON u.id = o.user_id;
-- Aggregate functions
SELECT category, COUNT(*), AVG(price)
FROM products
GROUP BY category
HAVING COUNT(*) > 5;
-- Subqueries
SELECT * FROM users
WHERE id IN (SELECT user_id FROM orders WHERE total > 1000);
Use EXPLAIN:
EXPLAIN ANALYZE
SELECT * FROM users WHERE email = 'test@example.com';
-- Look for:
-- - Sequential scans (add indexes)
-- - High cost values
-- - Nested loops on large tables
Add Indexes:
-- Single column index
CREATE INDEX idx_users_email ON users(email);
-- Multi-column index
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at);
-- Unique index
CREATE UNIQUE INDEX idx_users_username ON users(username);
-- Partial index
CREATE INDEX idx_active_users ON users(email) WHERE active = true;
Tables:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
total DECIMAL(10,2) NOT NULL,
status VARCHAR(50) DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Add Column:
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
-- Add with default
ALTER TABLE users ADD COLUMN verified BOOLEAN DEFAULT false;
Modify Column:
ALTER TABLE users ALTER COLUMN email TYPE VARCHAR(320);
ALTER TABLE users ALTER COLUMN name SET NOT NULL;
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
-- With error handling
BEGIN;
-- operations
SAVEPOINT sp1;
-- more operations
ROLLBACK TO sp1;
COMMIT;
Pagination:
SELECT * FROM products
ORDER BY created_at DESC
LIMIT 20 OFFSET 40;
Upsert:
INSERT INTO users (email, name)
VALUES ('test@example.com', 'Test')
ON CONFLICT (email)
DO UPDATE SET name = EXCLUDED.name;
Window Functions:
SELECT
name,
salary,
RANK() OVER (ORDER BY salary DESC) as rank
FROM employees;
Use /sql when working with databases, optimizing queries, or designing schemas.