r/SQL • • Sep 09 '26

Discussion How much SQL do you still write manually?

With AI getting better at writing SQL, I’ve been wondering how much SQL analysts actually write from scratch these days.
Do you still write most of your queries manually, or do you use AI for things like joins, CTEs, debugging, optimization, etc.?
And has your use of AI actually changed how much SQL you need to know?

115 Upvotes

240 comments sorted by

View all comments

31

u/ElHombrePelicano Sep 09 '26

I still write everything 100% myself. The generative AI sql outputs I’ve gotten have been absolutely terrible. Turns a simple 10 line query into a multiple CTE mess.

6

u/wirbolwabol Sep 10 '26

I don't need AI to write my CTE messes, I do those all myself!

3

u/metric_skeptic Sep 09 '26

But you can also ask it to find a shorter alternative. Sometimes it comes up with a surprisingly elegant solution that I wouldn’t have thought of myself. I still review the logic, but that’s one of the things I find really useful about AI.

9

u/Ginger-Dumpling Sep 09 '26

As someone who knows a couple dialects pretty well who sometimes uses AI to figure out equivalents/differences when porting over to other DB flavors/versions, I'm regularly presented SQL that is not syntactically valid for the targets I ask about.

I would say that I 95% write everything myself. I'm in an environment where I can't upload schema details, and even if I did, I would probably still have to document all the data anomalies I know I have to deal with before I could remotely consider generating sql from prompts. Pair that with an editor that has templating and auto-complete, I can churn out reliable SQL faster. Stuff that has to be repeated is in views, functions/procedures, materialized in some way, etc.

1

u/RICHUNCLEPENNYBAGS Sep 09 '26

You really want to have a way it can self-verify to iron out that kind of stuff if you want to have AI writing stuff for you. Otherwise it’ll just waste your time.

7

u/ElHombrePelicano Sep 09 '26

Ya, I’ve tried. It’s simply not smarter than me in any way.

0

u/rali3gh Sep 09 '26

Just to say, I wouldn't say it's 'smart' at all. I know this probably sounds pedantic, but I only say it because when I use it, I find I have to keep reminding myself of this.

The more I'm able to approach it as a tool to complement my own 'smarts' rather than mindlessly anthropomorphize it, the more productive I am while using it.

0

u/ElHombrePelicano Sep 09 '26

Wow… that’s deep.

-2

u/kilopeter Sep 09 '26 edited Sep 09 '26

What models have you tried?

I'd bet good money Opus 4.6 or ChatGPT Terra will nail your 10-line query given the same context you use to.

I hate job displacement as much as the next SQL wiz, but you're delusional or inexperienced if you think modern AI can't oneshot any given 10-line query.

4

u/ElHombrePelicano Sep 09 '26

Who are you people? Yes, I’ve tried both of these models and they do not come anywhere close to instilling the sort of confidence y’all have in them. I would be terrified to have y’all executing anything in my prod environments.

-4

u/kilopeter Sep 09 '26 edited Sep 10 '26

Im a veteran DBA who hasn't written a line of SQL in 1.5 years 10 months, since the release and rapid adoption of Anthropic's 4.5 series models in Claude Code.

You changed your answer from "AI turns what should be a 10-line query into a multiple CTE mess" to "these specific models don't instill confidence for prod execution."

What's an example of a 10-line query you claim AI makes a hopeless mess of?

---

EDIT:

I misremembered when the 4.5s launched. My bad, it's "only" been since late Nov 2025 that I haven't had to write any SQL directly. I blame insomnia and probably AI overreliance rotting out my brain's calendar math.

2

u/According_Basis7037 Sep 10 '26

I don’t believe you

0

u/kilopeter Sep 10 '26

Shit, i misremembered when Anthropic's 4.5 models came out (sleep deprived posting and quite possibly AI brainrot at work). Will edit

3

u/ElHombrePelicano Sep 09 '26

Changed my answer, or provided another statement? I’m not engaging with your flawed logic anymore.

-2

u/kilopeter Sep 09 '26 edited Sep 09 '26

10 lines or a stratascratch link should come easily to a smart guy like you, right? I'll await your example or assume you can't find one.

You're the one who brought in the 10-line query fail. For my own learning, I'm begging you to please share such an example to back up your already quite specific claim.

2

u/mkt853 Sep 10 '26

A DBA that hasn’t written a line of SQL in 1.5 years? I’m calling bullsh1t on that one unless there’s some catch like you’re running a toy database or one that doesn’t use SQL.

0

u/kilopeter Sep 10 '26

My bad, it's only been since Nov 2025. My date math broke. I edited my post

0

u/dbrown122 Sep 09 '26

Idk what AI you are using, but I have not found that to be the case, my job has SQL Authoring skills and it churns out some decent SQL. That being said, I am more cautious and only recently started to see what it can do.

-4

u/elevarq Sep 09 '26

This sounds like a problem with the input, that results in bad output

7

u/ElHombrePelicano Sep 09 '26

Wow……. 🤯 why didn’t I ever think of that? /s

-2

u/elevarq Sep 09 '26

The better models have 1M tokens context window. That’s about 650k to 750k words. The average book has about 70k words.

When you need to add about 10 books as context for a single SQL statement, something is wrong. There are hardly any applications that have so much documentation!

2

u/ElHombrePelicano Sep 09 '26

I’m not sure what you’re trying to convince me of.

2

u/CalebAsimov Sep 09 '26

Can you ask AI to convince us, cause you aren't doing a great job at it.

0

u/elevarq Sep 10 '26

Why should I convince you? It's your job that's on the line, not mine. I am convinced we should learn how to manage AI and get the best results from it. When it comes to skills, AI knows far more than we do and learns much faster; there is no way we humans can compete with it.

So instead of competing with it, we spend time learning how to benefit from it. And it works. Also for complex code.

But it's up to you

→ More replies (1)

1

u/ddBuddha Sep 09 '26

The size of the context isn’t tied to the quality of the output like that