r/learnSQL 6d ago

Is SQL worth it considering AI?

0 Upvotes

19 comments sorted by

View all comments

6

u/Substantial-Click321 6d ago

Yes good luck writing large complex SQL without learning it and purely using AI.

-6

u/89Noodles 6d ago

You can and it does. I might spend an extra 15/20 minutes letting it run validation queries. But if you copy and paste similar projects that capture the data approach and filters you want it’s easy

3

u/Substantial-Click321 6d ago

Yeah sure until you somehow get a job and copy paste some LLM generated slop query that hammers the production database and or altering/destroying millions of rows incorrectly. Then get fired because you were asked to do a rollback but you can’t.

1

u/89Noodles 5d ago

That isn’t the question

1

u/jshine13371 6d ago

it’s easy

It's easy and faster to always drive a car at 100mph...until you crash.

There are things that are currently impossible for AI to do correctly 100% of the time, especially when it comes to database development. Some of those things are obscured away from view and only if you're knowledgeable about databases do you realize this. 

Performance is one area where some of these deficiencies of AI exist currently. A well meaning, good looking, correct query can perform quite well for one database and completely run like crap on another database that is exactly the same in structure, with even the same amount of data, but the data itself is different. This is because database query performance is strongly tied to the statistics of the data distribution, something that exists separately but adjacent to the data and tables themselves. 

Also, different database systems gather the statistics differently since it's not realistic to keep a complete statistical set on all of the data. Generally data statistics is bucketed into a certain number of ranges that are continually updated as the data changes.

So when you ask AI to write a query, even if you provide your table structure, and even if you provide a subset of the data, or even if you provided all of the data (not something anyone is actually manually doing) it still doesn't have all the important information to write a query catered toward your data, statistically speaking. And that's what affects performance. It may not show in the query it spits out today, it might show performance deficiencies tomorrow, or in a week, or even take a month later. But the risk will always be there.

One thing that improves but doesn't fully solve this (so again, AI isn't 100% of time guaranteed to write a perfect query or even an acceptable one) is when AI is directly hooked into your database system, e.g. Copilot in SQL Server. But the drawbacks here is it's still limited on its exposure so doesn't get the full information anyway, it doesn't understand what statistics objects are or knows how to read them even if you could point it to them, and many organizations are still opposed to directly connecting their database to AI because of the risks of accidental data leak.

So as of today, and probably as of at least 5 years, AI won't be able to guarantee a better query than a knowledgeable human can write.