SQL (Structured Query Language) is a domain-specific language used for managing and manipulating relational databases. It is particularly useful for handling structured data where there are relations between different entities/variables of the data.
SQL Anti-Patterns Overview
Using SELECT *
SELECT *
in production code. Instead, explicitly list the columns you need. This improves performance by reducing I/O and network traffic, prevents issues when table schemas change, and makes your code more maintainable by clearly showing which columns are being used.Not Using Parameterized Queries
Inefficient Joins
Not Using Indexes Properly
Using DISTINCT Unnecessarily
Using Cursors Instead of Set-Based Operations
Not Using Appropriate Data Types
Storing Comma-Separated Values
Not Using Transactions
Using NOT IN with NULL Values
Using COUNT(*) to Check Existence
Using OFFSET for Pagination
Using OR Conditions on Different Columns
Not Using Common Table Expressions (CTEs)
Using Implicit Conversions
Using Scalar User-Defined Functions in WHERE Clauses
Not Using Schema Names
Using Table Variables When Temporary Tables Would Be Better
Using DELETE Without WHERE
Not Using MERGE for Upserts
Using Non-Standard SQL
Not Using Appropriate Constraints