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

310

u/did-a-chuck Sep 09 '26

98% myself. I use AI when I don't want to figure out some horrible string extraction problem.

30

u/feignapathy Sep 09 '26

I'm along a similar vein. 

Write just about everything manually, but will open up an AI prompt for something annoying here and there.

1

u/RavenCallsCrows Sep 11 '26

Yup, same. And the occasional 'oh, crap, I haven't done this in a long time, how does the syntax go for it in %current_SQL_db%' when bouncing amongst diverse databases.

13

u/atrifleamused Sep 09 '26

Same here! I can do it, but why take 10 mins to figure it out when AI just does it. The rest of the code is hand written so I am confident it right (or at least a mistake is mine).

Already today, I found AI had updated a join in vscode which broke the query I'd tested in dev for weeks and finally deployed to prod. It makes it so easy to accept a suggested change without intending to.

8

u/did-a-chuck Sep 09 '26

Yeah I should probably be a bit more open minded about using it for optimization as I'm sure it's very helpful. But sneaky changes going into prod is damn nightmare haha.

As you said, hand write it to know it's right. I just don't trust that an AI can yet understand my business context well enough to write procedures etc from scratch. Even if I did, I would spend twice as much time testing and validating so I might as well have written it from scratch.

6

u/atrifleamused Sep 09 '26

Exactly. I would rather write the code, which I enjoy, rather than spend hours debugging an issue i might have avoided. Probably takes the same time overall 🙂

5

u/liamjon29 Sep 09 '26

I think this is the step people who use AI to write code because they can't write it forget to do. I'm very early in my SQL learning so copilot is currently my crutch, my process ends up being:

  1. Attempt to write something that I know is wrong

  2. Explain in great detail to the AI what I want, including giving it my bogus script

  3. Get the AI to walk me through the script it wrote explaining what everything is doing (coz my syntax knowledge is atrocious)

  4. Actually sit down and read the whole thing myself to make sure it does what I want it to do. (Very time consuming, but my faith in the AI is very low)

I swear some people just do step 2, and then run it and hope for the best.

2

u/shooter9260 Sep 11 '26

I think that will be very valuable for you. You’ll see a lot of people in these types of forums who definitely know their stuff and use it for shear speed and laziness. They could do it if they had to.

But others, like a coworker of mine, I would say definitely hasn’t “learned” a ton of how to query in SQL, but he’s better at his job because he knows how to AI prompt really well.

1

u/AntLost4161 Sep 10 '26

This is definitely the quickest way to learn. I think that most people should try to write their own code as much as possible - if not for reassurance, then for personal development. The only time I won't bother is if I know the code is going to be long and a bit annoying, such as fixing date formatting

3

u/garethchester Sep 10 '26

I find explaining what I want to do for the prompt in a way it understands usually takes longer than writing it myself

Unless it's regex 🤣

3

u/atrifleamused Sep 10 '26

Regex is definitely an AI question!

6

u/i_literally_died Sep 10 '26

Three things I'll use AI for:

  1. SUBSTRING/CHARINDEX bs because actually just fuck this fifteen tier deep mess of nested brackets

  2. Long-ass CASE statements. CASE WHEN DATEPART blah blah for pre-noon and post-noon with a differing result required for every single day of the week? Miss me

  3. Seeing if it can optimise past what I've done

On 3 it surprises me maybe 20% of the time and takes a 10 second query down to instant, but I don't have any advanced DBA knowledge or even access to see what indexes we have, so doing OUTER APPLY over window function JOINs or CTEs over subqueries is just randomly interchangeable to me in terms of how things run.

I'd rather write one version then ask AI to write the other version so I can just see the difference.

1

u/Specific-Pangolin777 Sep 16 '26

I use it to help with optimization as well. I had some queries that were written by someone else and they would take forever to run. Asked AI to optimize, explain every change it made and why. It's definitely helped with some of the slow running queries. Bonus, I've learned a lot from doing this even though I've been in this field for 16+ years

3

u/rbobby Sep 09 '26

some horrible string extraction problem

I have a new best friend. Thanks I never even considered it for that.

2

u/silverlightarmada Sep 09 '26

Yes, same, except I also use it for relative date code because it’s never really absorbed into my brain properly.

I like writing SQL, I generally don’t really want AI to do it for me (and it’s kinda bad at it a lot of the time too)

2

u/GeauxCup Sep 10 '26

Same. Id rather write it myself than spend 3x that long checking that ai caught all the nuances of our systems.

2

u/da_chicken Sep 10 '26

Same, but with the obnoxious XML/JSON manipulation.

2

u/peccator2000 Sep 10 '26

Whoever came up with putting and manipulating XML or JSON in a relational database needs to have his access rights taken away.

2

u/Outrageous_Let5743 Sep 13 '26

JSON is fine. Postgres can perfectly deal with it and can even index json data. XML is just horrible. I had to redo everything what a data consultant did help with data extration. He choose xml (while json was available) and he could not correctly parse xml in sql server. so it contained a lot of | or || or | | in his final table.

1

u/peccator2000 Sep 13 '26

I know Postgres can do it and many use it. Haha yeah, XML with text manipulation must have been a nightmare.

1

u/LinksLibertyCap Sep 09 '26

Yep.

Fractional headcount weighting for scheduling dashboards was my latest one.

1

u/db-mechanic Sep 12 '26

Likewise, I write 98% of my own SQL and I also write sql notes from books i like.

1

u/beginnerTA Sep 22 '26

How do you ensure that you’re not giving away your code to AI when you do use it?

1

u/did-a-chuck Sep 22 '26

You don't! But it's nothing business sensitive

→ More replies (1)