Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Universal SQL code review assistant that performs comprehensive security, maintainability, and code quality analysis across all SQL databases (MySQL, PostgreSQL, SQL Server, Oracle). Focuses on SQL injection prevention, access control, code standards, and anti-pattern detection. Complements SQL optimization prompt for complete development coverage.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-03 | ✗→✓ | ▲ Improved | 113% | 0% |
| case-22 | ✗→✓ | ▲ Improved | 141% | 0% |
| case-16 | ✓→✓ | = Same ✓ | 134% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 109% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 140% | 0% |
Perform a thorough SQL code review of ${selection} (or entire project if no selection) focusing on security, performance, maintainability, and database best practices.
sql-- ❌ CRITICAL: SQL Injection vulnerability query = "SELECT * FROM users WHERE id = " + userInput; query = f"DELETE FROM orders WHERE user_id = {user_id}"; -- ✅ SECURE: Parameterized queries -- PostgreSQL/MySQL PREPARE stmt FROM 'SELECT * FROM users WHERE id = ?'; EXECUTE stmt USING @user_id; -- SQL Server EXEC sp_executesql N'SELECT * FROM users WHERE id = @id', N'@id INT', @id = @user_id;
sql-- ❌ BAD: Inefficient query patterns SELECT DISTINCT u.* FROM users u, orders o, products p WHERE u.id = o.user_id AND o.product_id = p.id AND YEAR(o.order_date) = 2024; -- ✅ GOOD: Optimized structure SELECT u.id, u.name, u.email FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE o.order_date >= '2024-01-01' AND o.order_date < '2025-01-01';
sql-- ❌ BAD: Inefficient aggregation SELECT user_id, (SELECT COUNT(*) FROM orders o2 WHERE o2.user_id = o1.user_id) as order_count FROM orders o1 GROUP BY user_id; -- ✅ GOOD: Efficient aggregation SELECT user_id, COUNT(*) as order_count FROM orders GROUP BY user_id;
sql-- ❌ BAD: Poor formatting and style select u.id,u.name,o.total from users u left join orders o on u.id=o.user_id where u.status='active' and o.order_date>='2024-01-01'; -- ✅ GOOD: Clean, readable formatting SELECT u.id, u.name, o.total FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.status = 'active' AND o.order_date >= '2024-01-01';
sql-- Use JSONB for JSON data CREATE TABLE events ( id SERIAL PRIMARY KEY, data JSONB NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW() ); -- GIN index for JSONB queries CREATE INDEX idx_events_data ON events USING gin(data); -- Array types for multi-value columns CREATE TABLE tags ( post_id INT, tag_names TEXT[] );
sql-- Use appropriate storage engines CREATE TABLE sessions ( id VARCHAR(128) PRIMARY KEY, data TEXT, expires TIMESTAMP ) ENGINE=InnoDB; -- Optimize for InnoDB ALTER TABLE large_table ADD INDEX idx_covering (status, created_at, id);
sql-- Use appropriate data types CREATE TABLE products ( id BIGINT IDENTITY(1,1) PRIMARY KEY, name NVARCHAR(255) NOT NULL, price DECIMAL(10,2) NOT NULL, created_at DATETIME2 DEFAULT GETUTCDATE() ); -- Columnstore indexes for analytics CREATE COLUMNSTORE INDEX idx_sales_cs ON sales;
sql-- Use sequences for auto-increment CREATE SEQUENCE user_id_seq START WITH 1 INCREMENT BY 1; CREATE TABLE users ( id NUMBER DEFAULT user_id_seq.NEXTVAL PRIMARY KEY, name VARCHAR2(255) NOT NULL );
sql-- Verify referential integrity SELECT o.user_id FROM orders o LEFT JOIN users u ON o.user_id = u.id WHERE u.id IS NULL; -- Check for data consistency SELECT COUNT(*) as inconsistent_records FROM products WHERE price < 0 OR stock_quantity < 0;
sql-- ❌ BAD: N+1 queries in application code for user in users: orders = query("SELECT * FROM orders WHERE user_id = ?", user.id) -- ✅ GOOD: Single optimized query SELECT u.*, o.* FROM users u LEFT JOIN orders o ON u.id = o.user_id;
sql-- ❌ BAD: DISTINCT masking join issues SELECT DISTINCT u.name FROM users u, orders o WHERE u.id = o.user_id; -- ✅ GOOD: Proper join without DISTINCT SELECT u.name FROM users u INNER JOIN orders o ON u.id = o.user_id GROUP BY u.name;
sql-- ❌ BAD: Functions prevent index usage SELECT * FROM orders WHERE YEAR(order_date) = 2024; -- ✅ GOOD: Range conditions use indexes SELECT * FROM orders WHERE order_date >= '2024-01-01' AND order_date < '2025-01-01';
`## [PRIORITY] [CATEGORY]: [Brief Description] **Location**: [Table/View/Procedure name and line number if applicable] **Issue**: [Detailed explanation of the problem] **Security Risk**: [If applicable - injection risk, data exposure, etc.] **Performance Impact**: [Query cost, execution time impact] **Recommendation**: [Specific fix with code example] **Before**:
-- Problematic SQL
**After**:-- Improved SQL
**Expected Improvement**: [Performance gain, security benefit]Focus on providing actionable, database-agnostic recommendations while highlighting platform-specific optimizations and best practices.
Other measured skills in the registry, with their headline benchmark lift.