5 SQL Habits That Make Your Queries Unmaintainable

●2 ●92 ●140
calendar_today • schedule2 min read

Most SQL problems aren't about syntax. They're about habits. The same bad patterns show up in every codebase, written by developers who knew better but were in a hurry. Here are five to stop immediately.

1. Single-line queries

SELECT u.id, u.name, u.email, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE u.active = 1 AND o.total > 100 ORDER BY o.created_at DESC LIMIT 50

This works. Nothing will break. But when you have to debug it at 2am — or when a colleague has to touch it — you'll regret every character on that line.

Fix: one clause per line, always.

SELECT
  u.id,
  u.name,
  u.email,
  o.total
FROM users u
INNER JOIN orders o ON u.id = o.user_id
WHERE u.active = 1
  AND o.total > 100
ORDER BY o.created_at DESC
LIMIT 50

Same query. Completely different to work with.

2. SELECT *

SELECT * FROM users

I know. It's fast to write. But it creates invisible dependencies — your application code may break silently when someone adds or removes a column. You also fetch data you don't need, which hits performance at scale.

Always name your columns. Yes, even for quick exploratory queries in development — the habit transfers to production code.

3. Implicit joins

-- Old style
SELECT u.name, o.total
FROM users u, orders o
WHERE u.id = o.user_id

This is valid SQL from the 1980s. It still runs. But mixing data relationships (the u.id = o.user_id filter) with data filters (business logic in WHERE) is a recipe for accidental Cartesian products and confused reviewers.

Explicit JOIN syntax is unambiguous:

SELECT u.name, o.total
FROM users u
INNER JOIN orders o ON u.id = o.user_id

4. Magic numbers in conditions

WHERE status = 2
WHERE type = 7
WHERE permission_level >= 4

What is status 2? What is type 7? You might know today. In three months, neither you nor anyone else will.

Use comments, constants in your application layer, or at minimum leave a comment in the SQL:

WHERE status = 2 -- 2 = active
WHERE type = 7   -- 7 = premium_user

Better yet, if your database supports it, use an ENUM or a lookup table.

5. No formatting before committing

Raw, unformatted SQL in migrations, stored procedures, and ORM raw queries gets committed and stays there forever. Once it's in the codebase, nobody reformats it — touching it means potentially breaking it.

The fix takes 10 seconds. Before you commit any SQL, paste it into a formatter. SnappyTools SQL Formatter handles 19 dialects (PostgreSQL, MySQL, SQL Server, SQLite, BigQuery, and more). Pick your dialect, choose your indent style, format, and copy. It runs in your browser — no setup, no signup.


Good SQL is readable SQL. These aren't academic style preferences — they directly affect how quickly bugs get caught in reviews, how fast new team members can understand the codebase, and how much time you spend debugging vs. shipping.

Pick the habit that's costing you the most time right now and fix it first.


Format SQL in seconds: SnappyTools SQL Formatter — 19 dialects, browser-based, no signup.

Originally published at https://snappytools.app/sql-formatter-beautifier/

Want more #webdev & #productivity deep dives?

Join 6,165+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelski - Apr 23

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

Three Design-to-Code Rules Most Developers Ignore (That Will Make You a Better Engineer)

Joemetry - Sep 26

Delivering Database Changes

Steve Fentonverified - Jul 22

5 Things This Playwright SQL Fixture Does So You Don't Have To

vitalicset - Apr 13
chevron_left
2.5k Points • 234 Badges
102Posts
0Comments
SnappyTools builds free, fast, browser-based tools for developers, writers, and designers. No signup... Show more

Related Jobs

View all jobs →

Commenters (This Week)

8 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!