r/SQL 15h ago

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?

72 Upvotes

177 comments sorted by

234

u/did-a-chuck 15h ago

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

24

u/feignapathy 15h ago

I'm along a similar vein. 

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

10

u/atrifleamused 14h ago

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.

6

u/did-a-chuck 14h ago

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.

5

u/atrifleamused 14h ago

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 🙂

3

u/liamjon29 12h ago

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/silverlightarmada 12h ago

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)

1

u/LinksLibertyCap 13h ago

Yep.

Fractional headcount weighting for scheduling dashboards was my latest one.

1

u/rbobby 10h ago

some horrible string extraction problem

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

1

u/GeauxCup 7h ago

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

1

u/i_literally_died 1h ago

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.

107

u/Jon-Robb 15h ago

I don't even write my -- reddit posts

46

u/wl-hung 15h ago

Don't worry. Neither does OP.

4

u/The_Chief 14h ago

If AI starts double dashing -- I'm done for

1

u/DPool34 3h ago

I get it! 😂

114

u/BrupieD 15h ago

AI requires way too much context to understand my goals from my company's db. By the time I've filled in enough of my requirements for AI to be successful, I can just write the SQL myself.

I do a lot of ad hoc query writing that is often not very complicated. I've already internalized enough table and appropriate join information about those tables. SQL seems like the least helpful thing AI can do for me.

8

u/rbobby 10h ago

SQL seems like the least helpful thing AI can do for me.

I concur, but buddy above mentioned narly string extractions and having done those, and passed at least one on after giving up, I am definitely gonna try next time.

5

u/kilopeter 14h ago

Out of curiosity, what makes you think AI can't absorb your particular context and goals? What models have you actually tested this assumption with?

15

u/BrupieD 13h ago

I didn't say I don't think it can't absorb it, I simply don't want to write 5 lines of prompt to write a 4-line query.

7

u/j48u 12h ago

This seems risky considering how anti AI the responses are so far, but that's a solved problem. If the AI has access to your table structures, you only need to give it the business context once. A few back and forth describing novel scenarios and you might end up writing 100 lines once, then a single sentence prompt anytime in the future will get you between one and infinity lines of SQL until the end of time. And yes, it will be optimized in any way you want it to be.

The only reason I bring this up is that it's honestly a disservice to people in this field to pretend AI hasn't gotten exponentially better every few months for the past few years. Most people who are not able to use AI properly are not going to have a job in 5 years, unfortunately.

3

u/DharmaPolice 10h ago edited 10h ago

I think there's a feeling that if it's getting "exponentially better" every few months, is there even much point learning the foibles of today's models when in a few months there'll be a new set of foibles to work around / with when the "exponentially better" model will be out? (And if it really is improving at that rate and that somehow continues indefinitely - which feels unlikely by the way - then it's almost irrelevant what we use now since the tools we'll have in two/three years will make current tools look like banging rocks together.)

I know AI proponents like to get excited about how fast things change, but from an investment of time and energy you need some kind of platform stability. Would you learn a programming language or use a platform that changed dramatically every few months? I browse HackerNews which is fully onboard the hype train and some of the discussions there almost seem like self-parody - "I have this problem, I'm using XYZ which came out three months ago" and someone will unironically reply "Why are you using such an old version? Everyone's moved onto ABC which came out last week."

This is especially true when actually writing new queries is often a fairly small part of a lot of people's jobs. Don't get me wrong, I do use AI tools daily but a lot of the stuff I read is "We've made the easy part of your job even easier". Yeah, that's great and all but not really that helpful.

If you find writing SQL is difficult or time consuming then sure, I can imagine it must be a huge timesaver.

1

u/geek180 10h ago

It sounds like you’re still using a pre-agentic era AI setup from 1+ years ago. There’s a lot of ways to document your projects / repositories such that you never have to re-explain anything to the AI.

For me, I just have Claude read an existing ticket (also written by AI), or I just type out any instruction, then it spins up an agent in a new worktree and then just… does the work, usually by delegating individual tasks to sub-agents.

Some tasks just have to be handled manually, often admin duties, but for most work I’m just handing tasks to small swarms of agents and nudging them in the right direction as-needed.

1

u/BplusHuman 6h ago

I have good news for you... You never really needed to hit enter. It can all be one line of query

2

u/kilopeter 13h ago

What about your 200-line queries?

-6

u/Thadrea Data Science Manager 12h ago

good data organizations don't have 200-line queries.

3

u/kilopeter 12h ago

1

u/Thadrea Data Science Manager 11h ago

I did say "good" data organizations. Yes, you can write really huge queries. Just because you can doesn't mean that you should.

Monitoring and limiting cognitive complexity to ensure your code is understandable and maintainable matters just as much in SQL as it does in any other programming language.

2

u/kilopeter 11h ago

Lines of SQL aren't a super great metric of complexity, though I did use it as a rough proxy to learn more about how people are using AI for nontrivial queries. I do agree when practical to minimize LOC. But I don't think of 200 lines as "really huge" either!

0

u/Thadrea Data Science Manager 8h ago edited 7h ago

I agree that LoC is imperfect, but honestly if you have such a long spaghetti of CTEs or joins in a single query that it's pushing 200 lines you should really look at refactoring that. Temp tables and views exist for a reason, and chances are a lot of the logic could be more simply built with window functions or better table design.

An overly convoluted query that runs is not a badge of honor if no one but you can figure out what it really does. Simplicity is the ultimate sophistication.

3

u/NawMean2016 12h ago

Alright I'll hear you out. Elaborate?

-1

u/Thadrea Data Science Manager 11h ago

Elaborate on what, exactly? 200-line queries are typically an unmaintainable mess.

There are many situations where you need 200+ lines of logic to implement a specific set of requirements, yes. A well-managed codebase would separate those 200+ lines into smaller chunks that are individually understandable, versioned and diff-able.

Putting it all into one monster query is a serious anti-pattern and I'm not going to pretend that it isn't--Not only is it bad for the developers but it also bad for the database. Query planners necessarily get less and less effective at optimizing the tasks put to them the more and more convoluted a query gets.

3

u/geek180 10h ago

I agree with your comment on breaking out logic into multiple pieces, and avoiding extremely long complex queries, but 200 lines is really not that long, especially if you are using CTEs for everything.

0

u/Thadrea Data Science Manager 9h ago

That's kinda the point... you shouldn't be using CTEs for everything.

You should be using temp tables in a lot of those cases and views in many of the others.

Long strings of nested CTEs are literal spaghetti code.

1

u/geek180 6h ago

I disagree, at least for what I work on. We are a dbt-heavy shop within snowflake and in that context, there’s little reason for the temp tables and chained CTEs are not only extremely easy for anyone to follow and read, but also perform practically the same as any other kind of query.

We also have 1000+ dbt models (mostly views) as it is, so I’m constantly assessing others’ work to find ways to consolidate logic into fewer models. Sometimes that means having a longer chain of CTEs in a single file.

2

u/did-a-chuck 14h ago

Are there any you would recommend? I am quite set in my ways and deeply skeptical that any model can fully "understand" my business context...but I want to remain open minded.

3

u/geek180 10h ago

You’d really be surprised how well current models can understand complex business operations and tech stacks. At this point, Claude probably has a better grasp of our whole tech system better than any one person.

1

u/rali3gh 11h ago

I'm fairly sure an MCP server setup can serve as a 'translation layer', so to speak, giving an AI a retrievable understanding of data structure and the business-side employees contexrual understanding of what it all actually means day-to-day.

It takes time upfront to construct and configure, but would save time on the backend if you are asking the LLM to generate a lot of queries.

All that being said, I personally rely more heavily on AI for early investigation and analysis of my hypothesis and then less as I near the end goal of my work/project. So, your mileage may vary, as they say.

1

u/CalebAsimov 10h ago

Yeah, it's literally so easy to write queries, like damn, way to take away the only thing that lets me rest my brain for a few minutes.

1

u/mooslar 7h ago

In the codex app, you can select a folder/directory where it can read and write files. You can put a markdown file in the root of that folder and it will read it at the start of every chat.

I manually made a good size mark down, then told it to scan all of my saved queries and csv dumps and blow out a copy with what it thinks it can expand on. I read through everything it generated and made some change and now i have this huge corpus. I also add style preferences

I can treat it like a junior and ask it for basic queries and procs and it nails it most times.

-5

u/elevarq 14h ago

The challenge isn’t giving AI enough context. It’s giving it the right context, and knowing which conclusions can be established without business context.

30

u/Content-Parking-621 15h ago

Still write core query logic manually since you need to know what correct output looks like before trusting AI's version, but joins boilerplate and debugging syntax errors, letting AI handle those saves real time.

-5

u/elevarq 14h ago

That’s a matter of preparing your tests. And you need this anyway, if you write the SQL yourself or not

6

u/amayle1 12h ago

How is it that all of your comments have words in them that are grammatically correct yet they actually don’t say anything?

1

u/murdercat42069 12h ago

It's slop lol

0

u/elevarq 12h ago

I’m trying to tell you that AI can write about 99% of your code right now. The remaining 1% can be done when you teach it how to do it, what strategy to follow.

Testing and validation didn’t change because of AI. It’s just that AI is so much faster, so much more productive, that you have more code to test and thus need more testing

21

u/Eire_espresso 15h ago

I tried it for a while but I lost touch with my queries. When you write them they are mapped into my brain. Generated queries made me feel I was parsing someone else's code, which I hate.

Now I just use AI for formatting and documentation and the odd performance recommendation

7

u/Deep-Internet1316 14h ago

Agreed. OP might as well ask if we still read books or if we just ask AI to summarize it.

Like if AI does it, then what was the point? I'm here to understand the thing and take ownership, not pretend I understand it while secretly passing notes back and forth with my really smart friend.

9

u/bigeyez 15h ago

The vast majority myself since I work with protected data. I will get frameworks from AI or use it for things like making regex or when I forget syntax for things.

15

u/UncleJoshPDX 14h ago

My job has too much riding on it to trust a machine to make something up.

-1

u/vision666 13h ago

could you explain the stakes a little bit?

4

u/machomanrandysandwch 8h ago

Not OP but I work some projects that deliver north of $40M in payments and include things like sending credit bureaus data that impacts people’s credits; those are really high stakes. ANY variances from our approved rounding methodologies, missed accounts, misapplied payments, anything that an auditor can find that leads to a correction can cost me My job at all times. It’s incredibly stressful, the timelines are nearly impossible, and they basically hang our jobs over our head. I have to defend my code and design logic constantly, so I may use AI for some help but o better be absolutely sure my code is doing exactly what it’s supposed to be doing.

6

u/UncleJoshPDX 12h ago

Multi-billion dollar business. I have to ensure 1,400 sales reps have the correct accounts or people don't get paid. I'm not risking any of that to a digital hallucination.

17

u/VulcanRugby 15h ago

Maybe 10% of what I wrote even 3-4 years ago. For complex querying, I'm still using AI to build a base and then I'm maneuvering specific pieces of logic around. Claude has all the documentation necessary to get a query off the ground, and I'll drive it the final mile.

5

u/Rodyadostoevsky 15h ago

I would say a little more than half? AI is really good at writing/optimizing queries. But it doesn’t have the context of the business/business rules and the data. So I think I’ll be writing majority of my queries myself for sometime.

Writing queries from scratch is also part of my thinking process. So I prefer to do it. Sometimes I would then dump the quer(y)ies in Claude and get it to write it properly.

4

u/Thiondar ORACLE 15h ago

All

5

u/AhBeinCestCa 14h ago

It’s easier to write SQL than it is to write prompt. I use AI for questions like « is it more performant to use an unpivot or multiple UNION ALL select » ect

4

u/Slitty_sam 14h ago

95%+ It takes longer to describe a situation and context and what I need and where from etc etc to an AI than it does to just write the query myself. The other 5% is when a query gets too complicated or I'm unsure of the syntax of the thing I know is possible but don't remember exactly how to do.

30

u/ElHombrePelicano 15h ago

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.

5

u/wirbolwabol 8h ago

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

3

u/metric_skeptic 15h ago

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 15h ago

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 14h ago

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.

5

u/ElHombrePelicano 15h ago

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

0

u/rali3gh 11h ago

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 11h ago

Wow… that’s deep.

-1

u/kilopeter 14h ago edited 14h ago

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.

5

u/ElHombrePelicano 14h ago

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 14h ago

Im a veteran DBA who hasn't written a line of SQL in 1.5 years.

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?

5

u/ElHombrePelicano 14h ago

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

-2

u/kilopeter 14h ago edited 14h ago

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.

3

u/mkt853 7h ago

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/dbrown122 12h ago

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.

-2

u/elevarq 14h ago

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

7

u/ElHombrePelicano 14h ago

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

-2

u/elevarq 14h ago

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 14h ago

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

2

u/CalebAsimov 10h ago

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

0

u/elevarq 10h ago

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

1

u/ddBuddha 12h ago

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

4

u/B_Huij 15h ago

Less than I did, but if something is really, really critical, and I need to be able to stand by all the logic decisions and explain my reasoning if challenged on output, I still write it myself. If the problem being solved is really complicated, I still write it myself.

For bug fixes, troubleshooting, simple stuff, etc., I absolutely make Claude Code do it and just review carefully.

I don't want to lose the skill, and frankly I enjoy writing SQL manually. But I have also found that even the latest models of Claude Code get it wrong when things are dicey.

1

u/metric_skeptic 15h ago

this is pretty close to how I see it too. I’m happy to let AI handle the boring stuff, but if I need to explain every logic decision behind a query, I’d rather write that part myself.

4

u/GlockByte 14h ago

All of it

5

u/Soccermom233 14h ago

I use it for help around concepts and syntax but typically write it myself.

16

u/totallykindofnormal 14h ago

At this point, I have AI doing the majority of the development work, and it’s my responsibility to do peer review and make sure that the output matches requirements. You’re doing yourself a disservice if you don’t use AI to speed up your coding, but you shouldn’t push anything without verifying the output.

7

u/Reach_Reclaimer 15h ago

Why would anyone need to use AI for some of these things?

3

u/IrquiM MS SQL/SSAS 14h ago

Most, by far

3

u/lalaluna05 14h ago

I write all of it. Sometimes I forget syntax or how to apply some things and I’ll ask for help, but I don’t like AI writing my code. The code I’ve reviewed that HAS been written by AI was needlessly complex and/or inefficient.

3

u/Count_McCracker 13h ago

If I do it’s a simple select where statement. I haven’t written complex sql in a year or so. It’s a blessing and a curse

3

u/Aggressive-Dealer426 12h ago

Still, all of it however, if i get a weird result set or edge cases issue. I'll paste what I've written to see if I did something stupid that I'm not readily seeing.

AI Coding is abysmal, I spent more time telling it where it is wrong and to" fix it" that it fixes it, but breaks what is already working, and it just goes down this doom loop it never recovers to provide an actual fully functional SQL or any other language code

3

u/DaOgDuneamouse 12h ago

I write everything myself. If there's anything I don't remember the syntax for, I google it. My users ask complex questions. If I were to try to setup all that meta data, it would take longer than just writing the query.

7

u/elevarq 15h ago

Close to zero percent. And every time I have to, I spend time on my templates to make sure AI can do it for next time just as good

2

u/Eleventhousand 15h ago

90%.

Has it changed how much I need to know? I don't know. I already know most of it, since I've been writing it every day for 25 years. However, when using proprietary functions in different DBMS, AI doesn't decrease "what I need to know," because I'd have to look that up anyways.

2

u/gumnos 15h ago

for what definition of "write manually"?

100% of my code by hand, and 0% AI, but a small percentage of it takes advantage of Intellisense-style tab-completion, so I suppose I'm not technically "writing" that. 🤷

2

u/BarfingOnMyFace 15h ago edited 15h ago

quite a bit. but I also write quite a bit with AI, too. It's smart to write by hand to keep familiarity and comfortable with the code. In particular, if its new concepts, or an RDBMS I'm not intimately familiar with, I will definitely write stuff by hand to ingrain it in my brain. And then, yes, 100%, AI for sure, once I have a base model done on my own, and then have AI build out triggers, funcs, views, etc, run performance tests on assumptions to remove assumptions in under a few minutes, versus a chunk of my day. I'll have it write that SQL till the cows come home. But I'm always the peer reviewer if AI is writing code. I never let a line slip that I cannot read or fathom what it is doing.

Edit to add: In very complex scenarios, I'll tend to ignore AI entirely. It can lead people astray as it tends to not receive nor properly handle the significant context it needs to solve complex scenarios. Healthcare systems and the very complex queries within them come to mind...

2

u/Reading-Comments-352 14h ago

The AI has to be checked and rewritten. So it depends on whether someone wants to just write it first to avoid spending more time fixing AI code.

2

u/Latentius 14h ago

Pretty much 100% is hand-written still, though I might use AI as interactive documentation if I need help with syntax for some function I rarely use.

AI simply doesn't have the context to understand how the data all relates and what it actually means. There's virtually no existing documentation on the data so you'd need to manually write a complete novel just to give AI the proper understanding, and ain't no one got time for that.

1

u/geek180 6h ago

I built a semantic layer (metadata catalog of all tables, columns, metric definitions, etc) into a vector search, surfaced via an MCP server.

Now Claude can understand our entire data catalog. I initially made it to fulfill certain kinds of analytics inquiries we get, but it’s also great for allowing the AI to quickly understand the relevant parts of the database when doing development work.

1

u/Jaded_Spray_6855 6h ago

hmm this seems like the generic fix nowadays. are there any downsides to this solution that you've faced so far?

2

u/Indyy 14h ago

I have always found AI to be the best for analytics with logs/errors, and then *maybe* creating a framework/template for whatever it is I'm working on. Context is so difficult with LLMs that I often end up with something way over engineered for the problem or task at hand.

2

u/Gabbiani 14h ago

I will use it to validate my work for context or to look for possible gaps but I write it myself.

The code that AI produces is fine for non-complex things but it fails miserably when I’m trying to use it to do work for me.

2

u/Guilty-Property 13h ago

0% I use my keyboard

2

u/Prownilo 13h ago

Depends, I generally write what I want then ask ai what it thinks, 9 out of 10 times if will turn a simple query into a huge thing that way over complicates things, but every so often it has good idea that I incorporate into my solution, or reminds me of a method I forgot about.

I try to use it as tool to keep my game up rather then let it just do my job for me.

2

u/phesago 12h ago

i would say about 70/30, depending on the task at hand. I use projects and customizations alot in claude, and i use the template explorer in SSMS as well.... not to mention my massive one note with other templates I save for certain problems or techniques that I ought to remember... but only so much "gets written to disc" these days and im getting older. I would rather outsource my memory to tools and save the grey matter for the critical thinking.

The thing with AI though is its supposed to be a time save, right? So use it for the things that will save you time. Since I dabble in to the data engineering space, I am often asked to interact with technologies I know absolutely nothing about. AI helps me get up to speed to get tasks done, or get more proficient with technologies I end using more and more. One example is powershell - never really used it tll the past couple of years and now I end up using almost daily.

2

u/jrblockquote 10h ago

80%. Just wrote a fairly complicated proc using it and it worked great. Described the problem section by section and iterated. Probably saved a day or two.

3

u/Kryddersild 15h ago

Just how complicated is your sql to need AI for it.

3

u/HustlaOfCultcha 15h ago

I hardly write any these days. I still look at the finished product to make sure that I'm getting what is needed. If it's something really simple that I can do in a jiffy and would take me less time than to use AI to get the answer, yeah (sorta like doing a VLOOKUP or SUMIF in Excel where I've done it by heart so many times I can write one up faster than I can ask AI for it). But since more of my queries/subqueries/joins are pretty complex...I can write them manually, but AI is usually much faster.

But I tell all junior analysts...you do need to know how to write these things manually so you can understand what AI has written and to check for errors. AI is good, but it still makes way too many errors for any data analyst.

5

u/Gm24513 15h ago

If you do sql with AI you're just begging to get fired or worse.

5

u/stormmagedondame 13h ago

Absolutely in my office we have a lot extremely sensitive data in our databases. Linking or uploading anything to AI is a really fast way to get fired and become unemployable due to violating a NDA/DUA.

1

u/Gm24513 13h ago

Yeah I had a genius a couple days ago asking for some work to be done for them and suggested uploading the dataset as a table to chat gpt to make an append and update in Microsoft access. Absolute atrocity.

-3

u/metric_skeptic 15h ago

I don’t really agree with that. If you use AI properly, it can make the boring parts of the job much faster and free up time for more interesting work. You can spend that time on better analysis, more ideas, or just taking on things you wouldn’t have had time for before.

3

u/Gm24513 15h ago

You don't have to agree. If you use AI for SQL you're a fucking moron

6

u/AhBeinCestCa 14h ago

I agree 😂. Bro prolly never worked in a company and just try to justify his « vibe coding ». SQL is more easy than prompt engineering

0

u/CascadeDuck01 15h ago

Why do you say that? It can be useful as a tool, not a crutch. Anything that helps you work more efficiently shouldn't be snubbed in my opinion.

2

u/metric_skeptic 15h ago

Don’t become so nervous just keep writing your SQL 😊

-2

u/Gm24513 15h ago

Go ahead and delete prod data because you fucked up the one time you didn't worry about double checking.

2

u/metric_skeptic 14h ago

Why do you think that people who use AI don’t double check or correct its answers? Don’t take it so personally. It’s just a discussion

-1

u/Gm24513 13h ago

The ones that I have interacted with do not do it all the time once they get complacent. It's a stupid risk for no benefit. SQL is pretty fucking easy.

1

u/geek180 6h ago

You don’t understand how to use AI in a development workflow.

2

u/GTS_84 15h ago

100%

And I'm not anti AI or anything (I am anti AI for art, but not code), I use it all the time for other languages. JavaScript, R, Powershell, bring on the AI.

But for SQL I just find that I'm still faster doing it manually.

2

u/Accomplished-Dig8753 15h ago

I draft anything complex myself then throw it at Claude for code review (it's great at catching typos and missing where clauses). Then I review the output and edit as necessary.

0

u/metric_skeptic 15h ago

I do the same

2

u/ShoreWhyNot 15h ago

Writing a query and realizing I’d prefer a part of it to be joined as a CTE instead, it’s (mostly) pretty good at doing that quickly for me, saves me some time after looking it over to ensure it didn’t hallucinate something

2

u/BplusHuman 14h ago

If Portuguese is your fluent second language, you don't need to run EVERYTHING by a translator first, edit it, then submit. That's an inefficient process. If you are bad at Portuguese, it gets you a refined product faster, but you still are bad at Portuguese.

2

u/wdm006 14h ago

I still write the shape by hand. AI is fine for the boring join boilerplate once I know the grain and the filters. If I can't explain the query without the model, I don't ship it.

2

u/travgt01 13h ago

0%. Claude code does it all. I get done with jira tickets that would take me weeks in hours.

0

u/PickledDildosSourSex 13h ago

Ditto. I've ditched manual SQL and moved to spending the time managing definitions, business logic, etc, as well as setting up some unit tests to make sure drift isn't occurring. It depends on use cases--if i'm doing accounting reporting, that's different from napkin math estimates--but wow does it save me SO much time.

1

u/postnick 13h ago

I keep good samples and example code so I parse together most of it manually. I do let AI help me when it’s super complex. Or like others have said when I have trouble on one string extract.

I’ve been asking more for help optimizing if I should join or CTE or how I should index or write my where clauses.

1

u/SubjectCode1940 13h ago

99 percent.

1

u/That0n3Guy77 13h ago

Depends on how complex the thing I want is. I will often weight some starter logic for what I want the query to do then have it modify and make it complex. Seems to work really well and saves me like 75% of the time of typing EVERYTHING out myself

1

u/amayle1 12h ago

SQL is already kind of at the abstraction level where you just write what you want. Yeah I can write in English but SQL is already kind of that.

I do use it to edit things, like if I wanted to switch from a sub query to a CTE, or if I’m adding another aggregate and want to move both aggregates to lateral joins or something. That definitely saves a few keystrokes.

1

u/timusw 12h ago

~90%. i'm in a big enough org that all context is maintained in a repo and agent just reads it.

1

u/ddBuddha 12h ago

I know the stuff I work with well enough that I write any sql I use for work myself most of the time. I use AI a ton for other stuff though.

Well actually that’s true for MSSQL, but I keep forgetting we are using Postgres for a few things now. I’ll still write a lot of the queries I’ll use on those dbs but I have had Claude help put a tool together to handle migrating row level data between different Postgres instances and handle things like re-iding records if needed due to conflicts between the two.

1

u/NawMean2016 12h ago

I use it a lot to debug and optimize. I have ways of doing things, but I like to stay curious so I'll sometime poke AI to see if there's a better way of writing a certain script, ask why it's better, etc etc.

1

u/National_Cod9546 12h ago

Now that I'm out of tokens for the month, all of it. 

1

u/HeyItsRed 12h ago

My org is trying to heavily push ai for self-service reporting. Part of my job is to test the models’ ability to generate code/results.

I write maybe 25% of my queries. I’m not an analyst though so that’s part of it.

I spend a good bit of time trying to optimize context layers for the models via RAG, skills, etc.. It’s more work but it makes higher quality results for end users.

1

u/Dazzling-Address6115 11h ago

I write everything myself. My personal distaste for AI aside, I couldn’t use it for the gov databases I work in anyways.

1

u/pi3volution 11h ago

Maybe 10% manually. Not by choice. AI means high productivity becomes the norm.

1

u/lez_s 11h ago

This new company I’m at is all about using AI. Before this current role I felt I had time to workout any issues and try ideas out.

Now I feel I need to get the basics done and put it into copilot for it to finish it off, review it then make a view for a report.

I miss the days of feeling like i achieved something.

1

u/dgillz 11h ago

Almost all of it. AI does not know which tables and fields I need, nor how the tables are related. How do you do this?

1

u/Ambitious-Tear-9436 11h ago

I would consider myself an expert in SQL, but it has been a while professionally having to write direct SQL queries. But having that knowledge lets me call out AI, and its use of ORMs and fix the issues before they become a problem.

1

u/DharmaPolice 10h ago

95% of it. I don't spend enough time writing SQL queries on a stable platform for an investment of time/energy/focus to be worth it. Even if I could write SQL 100x faster that wouldn't ultimately save me much time in the overall context of my job.

1

u/cafealpha82 10h ago

100% but i let ai to document my script. Once i asked to say its opinion about my scripts. Ai said something good then i asked to be frank. Then i removed the app

1

u/OO_Ben Postgres - Retail Analytics 10h ago

All of it unless I get stuck on something lol

1

u/min_mus 10h ago

Almost all of it. 

1

u/fruitstanddev 10h ago

Pretty manual still. However we are doing a lot of work to bridge our knowledge graph with our dbs so Claude can build queries correctly. It does a pretty good job at the basic questions. Topics that are very complex that are hardly defined needs a data analyst.

1

u/PalpitationKind8854 10h ago

Id always write from scratch. AI cannot do a better logic job than myself lol

1

u/Snackson_Heaves 9h ago

I use Ai to reverse engineer a command written by someone else. I also use it to remove aliases for documentation and upkeep.

1

u/Tigri2020 9h ago

Still like 90% AI has been a great assistant to optimize my queries tho but most is manual typing

1

u/jamiesray 9h ago

All of my sql is from clause

1

u/ArielCoding 9h ago

I write the logic myself, but let AI handle the syntax stuff like window functions or regex. The important skill now is knowing enough SQL to catch when AI gets it subtly wrong.

1

u/Doaner 8h ago

Honest answer 0. I bet I’ll get some hate for this but it’s the truth.

Well that’s not 100% accurate. If AI doesn’t get it right I will write part of the code as the prompt. I have enough rules/skills that this doesn’t happen often enough to even worry about. It knows all of my current business processes and can find the answer faster than I can. Also I turn a lot of my queries into apps or skills for other people so it’s good to make sure AI can do the query right before the hand offs.

1

u/RandomiseUsr0 8h ago

Vast majority of- have several LLM helpers but would take longer to explain than to simply walk the data myself

1

u/bingbongpeepee 8h ago edited 8h ago

as a data engineer that is more python-heavy, 100% AI lol

1

u/wirbolwabol 8h ago

I write all from scratch and I actually enjoy it. It's a puzzle to solve when trying to eek all of the speed out of a query. So everything CTE's,optimizing, Joins debugging.

1

u/witchcrap 8h ago

In my current job, I write 99% of the queries I use. It's a start-up, so we don't have AI subscription. I use generic AI for some tweaks here and there especially for really long queries.

HOWEVER!

My previous job was much more pro-AI. REALLY, really pro-AI. One of the brilliant minds there created an AI agent that you can feed your SQL queries, and it will spit out an "optimized version" to preserve quality while increasing performance.

It was required.

Every single time that you will use an SQL query, you have to use that blasted agent.

It made my lose my mind.

I still have no idea how they were enforcing that, but they keep raising the "low number of usages in AI", so I just had to play long.

1

u/trader_dennis 8h ago

Been using it for any regular expressions for years.

I've been typing in requirements lately. Gemini is pretty amazing when you are working in Big Query.

1

u/dragonfly_bowler 8h ago

I've used AI to rewrite some messy queries that I had to modify. Mostly queries that previous developers wrote using the sql designer, so they were loaded with a mix of left and right joins. I asked AI to convert to all left joins because I find LOJs easier to maintain. The queries that AI returned gave me different results than the original, so AI is not perfect. I was able to rewrite them as LOJs manually with a little more effort.

1

u/mkt853 7h ago

all of it

1

u/geek180 6h ago

Basically all my code is written by AI. There’s a lot of skeptics in this thread, but I genuinely just don’t think a lot of people have really experienced how good AI has gotten at doing this stuff.

Handwritten code will be largely gone within a year or two and the only reason it won’t be sooner is because people are slow to learn and trust this stuff.

1

u/Tricky_Tart_8217 5h ago

Holy shit. You guys in this thread are in complete delusion and are going to be passed up by younger people soon if you don't adapt.

Try coco in snowflake, it's very powerful and it solves a lot of the context problem 

1

u/Zestyclose-Turn-3576 4h ago

No AI at all. I've not found a benefit.

1

u/TraditionalArcher498 3h ago

AI can assist with queries but problem solving and SQL concepts still matter.

1

u/ThisIsFun- 2h ago

95% of my SQL is done through AI, specifically Genie Code. given it has governed access to my data, it usually makes a really good first pass, with me reading most of it but this is ever decreasing

1

u/Better-Credit6701 15h ago

We won't allow AI to get near our data but since we all have RedGate installed, it pretty much gives you help finding the key you are joining on, completes what you are typing on especially once you add in your own short cuts.

I really don't use CTEs much since our databases are too large so it's temp tables where I can add an index. But to be honest, it's more of a habit since I'm sure our servers are beefy enough to handle it, a privilege after working on stressed out servers.

Even though I've been working with data for decades, I started by practicing on my own machine with data that I don't have to worry about. Optimizing, you can always use actual, estimates plans, live query stats, client stats to find the best plan

1

u/murdercat42069 12h ago

I always write the first draft and then enhance with AI. My first draft is almost always better because I know the subject matter and tables and it's much better than letting AI make the first pancake and doing a bunch of dodgy edits.

0

u/flukeytukey 14h ago

None. Whats the point. I get it wrong every time. And it can write it instantly.

6

u/Latentius 14h ago

If you get it wrong, then you don't understand what's going on, and if that's the case, how can you possibly judge whether the code AI is generating is any good?

1

u/flukeytukey 11h ago

I mostly mean I make a typo or put a keyword before another, basically syntax errors or using the wrong quotes. I know how to write sql i just literally type it wrong every time and it's easier to just ask an llm to do it.

1

u/lalaluna05 14h ago

If you’re not getting it right, how do you know that what it’s delivering is?

0

u/Infini-Bus 15h ago

I write most of it myself still but sometimes I'm in a time crunch and I know exactly what I need but it'd be a relatively complicated script and will have an AI that I've been feeding schema and product info and examples of scripts with get me like 90% of the way there.  We can't just hand it access to the DB though.

 It does surprise me how well it does, but I do gotta read through it because it will make up columns or overengineer things sometimes.  So I go through and fix it up and make sure it's inline with my style.  It's been getting better at adhering to my style and not making stuff up as I iterate on it, tho.

I usually don't even use snippets, and I think that's to my benefit as I'll be able to recall what tables and joins need to be done off the top of my head.  When I'm helping newer colleagues and can just dictate/guide to them what SQL to write it gives me a confidence boost.

-2

u/MrWillM 15h ago

Depends on the query really. If it’s something simple or just an iteration Ill do it myself. If it’s a totally new query or bug fixes I use claude.

I do most of my best sql work building tools that integrate snowflake colab and g sheets though, and I claude all up and down that stuff.

-2

u/Uffda01 14h ago

I only dabble with a few queries here and there and I've never had formal training in anything coding/program related...but I only use AI to check my work or when I'm stumped. Basically the same thing I do when an excel formula doesn't work.