sql-code-review

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 opti

By github · 13,078 installs

npx skills add github/awesome-copilot --skill sql-code-review

Source repository · Upstream listing

SQL Code Review Perform a thorough SQL code review of ${selection} (or entire project if no selection) focusing on security, performance, maintainability, and database best practices. 🔒 Security Analysis SQL Injection Prevention Access Control & Permissions Principle of Least Privilege : Grant minimum required permissions Role Based Access : Use database roles instead of direct user permissions Schema Security : Proper schema ownership and access controls Function/Procedure Security : Review DEFINER vs INVOKER rights Data Protection Sensitive Data Exposure : Avoid SELECT on tables with sensitive columns Audit Logging : Ensure sensitive operations are logged Data Masking : Use views or functions to mask sensitive data Encryption : Verify encrypted storage for sensitive data ⚡ Performance Optimization Query Structure Analysis Index Strategy Review Missing Indexes : Identify columns that need indexing Over Indexing : Find unused or redundant indexes Composite Indexes : Multi column indexes for complex queries Index Maintenance : Check for fragmented or outdated indexes Join Optimization Join Types : Verify appropriate join types (INNER vs LEFT vs EXISTS) Join Order : Optimize for smaller result sets first Cartesian Products : Identify and fix missing join conditions Subquery vs JOIN : Choose the most efficient approach Aggregate and Window Functions 🛠️ Code Quality & Maintainability SQL Style & Formatting Naming Conventions Consistent Naming : Tables, columns, constraints follow consistent patterns Descriptive Names : Clear, meaningful names for database objects Reserved Words : Avoid using database reserved words as identifiers Case Sensitivity : Consistent case usage across schema Schema Design Review Normalization : Appropriate normalization level (avoid over/under normalization) Data Types : Optimal data type choices for storage and performance Constraints : Proper use of PRIMARY KEY, FOREIGN KEY, CHECK, NOT NULL Default Values : Appropriate default values for columns 🗄️ Database Specific Best Practices PostgreSQL MySQL SQL Server Oracle 🧪 Testing & Validation Data Integrity Checks Performance Testing Execution Plans : Review query execution plans Load Testing : Test queries with realistic data volumes Stress Testing : Verify performance under concurrent load Regression Testing : Ensure optimizations don't break functionality 📊 Common Anti Patterns N+1 Query Problem Overuse of DISTINCT Function Misuse in WHERE Clauses 📋 SQL Review Checklist Security [ ] All user inputs are parameterized [ ] No dynamic SQL construction with string concatenation [ ] Appropriate access controls and permissions [ ] Sensitive data is properly protected [ ] SQL injection attack vectors are eliminated Performance [ ] Indexes exist for frequently queried columns [ ] No unnecessary SELECT statements [ ] JOINs are optimized and use appropriate types [ ] WHERE clauses are selective and use indexes [ ] Subqueries are optimized or converted to JOINs Code Quality [ ] Consistent naming conventions [ ] Proper formatting and indentation [ ] Meaningful comments for complex logic [ ] Appropriate data types are used [ ] Error handling is implemented Schema Design [ ] Tables are properly normalized [ ] Constraints enforce data integrity [ ] Indexes support query patterns [ ] Foreign key relationships are defined [ ] Default values are appropriate 🎯 Review Output Format Issue Template sql Problematic SQL sql Improved SQL Summary Assessment Security Score : [1 10] SQL injection protection, access controls Performance Score : [1 10] Query efficiency, index usage Maintainability Score : [1 10] Code quality, documentation Schema Quality Score : [1 10] Design patterns, normalization Top 3 Priority Actions 1. [Critical Security Fix] : Address SQL injection vulnerabilities 2. [Performance Optimization] : Add missing indexes or optimize queries 3. [Code Quality] : Improve naming conventions and documentation Focus on providing actionable, database agnostic recommendations while highlighting platform specific optimizations and best practices.