question

Matt Whitfield avatar image
Matt Whitfield asked

Is SQL on the way out?

Ok, so I will be the first to admit that, in language definition terms, SQL is horrible. Having written a code completion engine for it, I think I can say in a reasonably qualified form that the language specification leaves a lot to be desired. Lexing is OK (despite a few weird rules) but Parsing SQL is really hard.

So along comes LINQ. For all the language definition reasons, it's way ahead, as it would be, it's a much newer language.

But I have to say, I just don't like it. While the language definition is much better, I don't think that it reads nearly as well. Sure, for a simple 'let's get one row back from the DB' then it's perfectly understandable - but I would imagine that most people here tend to do a lot more than that while generating reports etc.

The other thing that scares me about it is the 'trendiness' factor. It's like you get kudos for using LINQ in whatever situation in some circles - and, in my experience, that has always lead a good technology to become a 'band-aid' solution which is used everywhere, no matter how inappropriate. Given how much I've learned about query optimisation through participation here (and being more of a 'lurker' on the main SSC site) I don't want the opportunity to exercise that knowledge to disappear - because, for the main part, efficient queries come from really understanding the data at hand, and I don't think it's possible for LINQ to have that level of understanding.

What are your thoughts? And apologies that this is a 'no-correct-answer' sort of question, accept for highest voted answer in 7 days...

t-sqldatabase-design
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered

No.

Oh you want some elaboration.....

For so many reasons, like Håkan mentions, SQL will not succumb to LINQ, or any ORM.

I'm not saying SQL won't change, but the fundamentals seem so firmly based and have stood the test of time, that it seems unlikely. What may change is the data model that gets used. Relational data isn't perfect by any stretch, but fits more scenarios than hierarchical data models, network data-models, eav models and whatever else has been tried over the last 30 years or so.

I accept that as a SQL professional, I am defensive about this, but to be honest every time another trendy alternative comes along, I just see it as an opportunity in-waiting, as surely a number of months/years down the line, the 'trendy' solution just can't cope and the data layer needs re-writing using good old SQL.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Håkan Winther avatar image
Håkan Winther answered

I have seen so many bad SQL statements written by developers and LINQ scares the hell out of me. I am afraid that with LINQ, even more developers will think that they can develop efficient database driven applications, and ignore the need for an experienced database developer, and in the end when the developers have left the building (consultants) the database performance will slowly degrades until the system is useless.

By then, when a DBA is involved trying to optimize the code, everything is build in C#, VB.NET or whatever, leaving the DBA without any options then add more hardware.

I think for small to medium sized databases,it is possible to write crappy code and the system still works (thanks to the hardware), but when it comes to large and huge databases it is not possible to solve the issues from crappy code with more hardware. The only solution is to modify the code.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David 1 avatar image
David 1 answered

Good question. SQL is surely a very poor platform for modern development needs. The fundamental language features of SQL DBMSs have improved very little in the last 30 years. Compare that to the major innovations in object-oriented languages over the same time period. Part of the problem is that the SQL model was fundamentally based on some flawed ideas and designed to work within the constraints of 1970s systems. The domination of the SQL DBMS market by three major corporations with vested interests in maintaining the status quo has also not helped.

I think the database management profession ought to be able to answer the question by saying "Yes, I hope so". We really ought to aspire to better things than SQL. I'm definitely not saying that LINQ is the right successor to SQL but at least it is one initiative that is showing some kind of way forward. The various products that go under the "NoSQL" banner are another example.

Unfortunately I think SQL database professionals have sometimes been a little too defensive about SQL and this has left them somewhat outside of the discussion rather than participating in it and putting forward alternatives. I think more data management professionals at the grassroots level need to recognise the need for new alternatives to SQL and contribute to the development of those future solutions. For instance, where are the relational-based alternatives to the SQL DBMS model?

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
Your comments are always thought-provoking... This one is no exception!
0 Likes 0 ·
TimothyAWiseman avatar image TimothyAWiseman commented ·
A very thought provoking example, and I agree that we should be looking for something better than SQL. The problem is that nothing has emerged that is *in general* better than SQL. ORMs have their place, but it is currently niche. The same with the NoSQL technologies. They are certainly better for some things. But for many things right now there is no better solution than SQL and I have not yet heard of anything on the horizon that I expect will get there. I can think of some tweaks to sql I would like to see, but fundamentally I cannot come up with a better alternative myself.
0 Likes 0 ·
Grant Fritchey avatar image
Grant Fritchey answered

As long as we have structured data, there's going to be a need for a language to query against it. That's not to say that SQL in it's current form is the way to go, but some type of language that is capable of dealing with pulling data out of relations within structured data is needed, and so far, none of the alternatives is more workable than SQL, in fact, most are less workable. Both literally and figuratively, in terms of an alternative to SQL, I'm from Missouri... Show me.

Until I see a fully functional alternative, I'm going to stick with SQL. That means that all the problematic ORM tools are going to remain, to a small degree, a thorn in my side. They don't deal well with SQL or relationships. They are, in my opinion, an attempt to ignore SQL, not replace it or deal with it. That, unfortunately, is the worst possible approach. Better to deal with it badly than try to pretend it doesn't exist and then generate all the horrors that I've seen & heard about.

However, get me a better method of querying the database, and I'm all for it. There's no reason to be married to a language. Based on the last 60 years of computing history and my own 20 years within it, we will get a different language eventually. Languages, OS's and platforms come & go. Nothing is carved in stone. But, at this time, there's nothing viable as an alternative that I can see.

6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
If you didn't live 4,212 miles away I'd be asking if you wanted to go down the pub and discuss what your thoughts on a better alternative might be... :)
1 Like 1 ·
David 1 avatar image David 1 commented ·
How about a D-language (such as Alphora D4) as a better alternative?
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Love to. Nothing better in the world than English beer.
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
I'm not familiar with that one, but I'll take a look at it when I have a second or two.
0 Likes 0 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
Let me know when you're in my neck of the woods then, sir...
0 Likes 0 ·
Show more comments
Steve Jones - Editor avatar image
Steve Jones - Editor answered

My first response is "no, SQL works well"

However the note by dportas is interesting. Should we be looking at a way to possibly evolve to a new language that works better? We have seen "C" evolve to C++, C#, and now F# in some ways. Python is a very interesting environment to me as well, but in spite of all the work done on languages, there's still a decent amount of C around, and I wonder how much C++ code is actually C compiled in a new IDE.

From what I've seen in terms of how we work with data, SQL works pretty well, but it has a decent learning curve and requires someone to fundamentally be able to understand how SETs interact. That feels like the pointer issues of my early career where lots of people just could not understand a pointer.

If I had to say that SQL fails in one place, and I've seen this with the intellisense challenges, is that it doesn't fundamentally order the commands correctly. In my mind we ought to decide what tables we are using first, then get columns and relationships. So something like

FROM Customers c
  Inner Join Orders o
     on c.custid = o.custid
SELECT c.customername, o.orderdate, o.ordernumber
 where o.orderdate > '1/1/10'

I think that we possibly could also find some other ways to create set interactions, or perhaps even have FKs automatically joined with a keyword, could build cleaner code. The whole change to using a CTE in SQL, with the code at the top, to me, means it's fundamentally harder to read. That was, in some sense, a step backward by bolting something on rather than fundamentally re-working the language.

I think LINQ wasn't a bad idea, but the way it translates into SQL is what I find problematic.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Scot Hauder avatar image Scot Hauder commented ·
MDX has had WITH clauses for some time now so I believe they added CTEs to SQL to create similar functionality. LINQ has the table/source first for precisely the reason you have indicated, to make intellisense work Your last sentence is the reason Matt will not have to discard his SQL knowledge any time soon. Eg You can write sloppy C# code and it will still seem to run as fast as optimized code. You can add more layers of abstraction to a language and it will seem to perform admirably.
1 Like 1 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Oh heck yes! That syntax change alone would make a huge difference in the functional understanding of SQL. Great point.
0 Likes 0 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
Agreed - +1... And I know about the FROM bit first - I put a mode into my engine where you type SELECT tablename. and then it changes it to SELECT schema.tablename. FROM schema.tablename - was the only way I could think of to address that one...
0 Likes 0 ·
Scot Hauder avatar image Scot Hauder commented ·
The same is not true for SQL, what may seem like modest change in logic or design of a query can literally alter the execution time from seconds to tens of minutes, or even hours. To formulate optimal SQL you need to have an intimate knowledge of the data, the schema, how users use it, the db platform and a deeper understanding of your problem domain, what you want to accomplish and how to translate that solution in a way that the db can carryout efficiently. LINQ knows little of this and must work with the lowest common denominator so it can be used with disparate data sources.
0 Likes 0 ·
Scot Hauder avatar image Scot Hauder commented ·
For this I am not a fan of Linq to SQL because I know my SQL knowledge can always outperform it, Linq to objects/xml is quite useful though. I think a great deal of improvement can still be made but translating what someone wants from a database into optimal SQL would be cost prohibitive and take too long to develop
0 Likes 0 ·
David 1 avatar image
David 1 answered

I think the point made by Scot Hauder in his comment is worth highlighting (although maybe his intended meaning wasn't the conclusion that I draw from it):

"what may seem like modest change in logic or design of a query can literally alter the execution time from seconds to tens of minutes, or even hours"

This is true and it perfectly illustrates what a failure SQL is as a database language. The point of Physical Database Independence is precisely that the logical should not determine physical. The SQL language's redundancy, over-complexity and lack of orthogonality mean that it utterly fails to do that.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Scot Hauder avatar image Scot Hauder commented ·
I agree, SQL also sets itself apart from many languages because it gives you the power, to a certain degree, to affect the physical (disk/data access) It's like having the power to drive a manual transmission--you may choose (innocently or not) to drive in first gear all the way to the store, it will just take a lot longer.
0 Likes 0 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
I can't think of many situations, either in real life or in computer science, where the what is truly abstracted from the how. Knowledge of how things work 'inside the black box' will always make you a more effective user of that black box....
0 Likes 0 ·
TimothyAWiseman avatar image
TimothyAWiseman answered

There are a lot of thought provoking comments here. I will avoid rehashing the ones that have been repeated over and over, but one thing no one has mentioned yet that I saw is how language specific the ORMs are. If you want to use Linq you must use a .Net language. If you want to use SqlAlchemy you must use Python, etc.

This will make it hard for any one ORM to gain dominance. The core of SQL is implemented in numerous databases though. They each have differences and quirks, but going from Oracle to SQL Server is like the difference between American English and British English, nontrivial but easy for someone who has mastered one to figure out the other very quickly.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

rpwt avatar image
rpwt answered
I'm a non-SQL expert but have been using it for 20+ years as a developer/admin. Every time I need to do something more complex than a few JOINs and subqueries it seems that I need to dig into the documentation and iteratively test various syntax forms before it starts to work. For those of you that live and breathe SQL, it probably flies off your finger-tips without errors and without requiring much conscious thought. When I have time to frame the query (or other CRUD) in a human-understandable fashion, most of my coworkers can deduce what I am trying to achieve and think that should be easily achievable. Yet it always takes several attempts to phrase it in SQL that ~may~ bring back some of the desired results. Perhaps playing multiple roles in most of the companies that I've worked in (DBA, web/app programmer, manager/marketer) gets in my way. If I were only an SQL programmer all of these fine points about SQL and LINQ and optimizations would be just what I would be looking for. My current job involves a DB that has evolved over 15 years (Access -> MSSQL). There has been a strong attempt to capture most of the business rules (and some UI) in a plethora of stored procedures and user-defined-functions. These procedural elements can't be organized in any logical/hierarchical sense (not supported in MSSQL) so we end up with 400+ objects that only their developers can understand. There is no class encapsulation of functionality that I know of other than invoking yet-another function that is in the same top-level hierarchy. OK, so too many peeves before I get to my main one: Our DB dataset is only around 2GB. We could suck this whole thing into a set of linked objects in memory and process them using almost any language other than SQL. Yet, there doesn't seem to be a good query language alternative that supports all of the conditional, joining, and selection logic of SQL. Any suggestions?
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
A couple... (1) This is really a new question... (2) perhaps separate the business logic from the database and use that to create your desired hierarchy / encapsulation of functionality.
0 Likes 0 ·
Johan Sivertsen avatar image
Johan Sivertsen answered
Idea triggered by reading the "non-SQL expert's" frustration with many non-grouped functions: It would be nice if SQL Server could **group objects** (functions, procedures, tables, views) into **user-defined groups/subgroups** *with the sole purpose of order* and thereby **saving time** getting an overview of a database. This will NOT change SQL and should be relatively easy to implement. PS! This should be a comment (and is going away from main question), but I cannot make comments. I think I need "50 karma points" to be allowed to comment.
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
Well, there is the concept of Schemas... they could be used for that purpose.
0 Likes 0 ·
Johan Sivertsen avatar image Johan Sivertsen commented ·
Thanks! I have considered for some time to use Schemas to make order of reports in a data warehouse I develop in an insurance company. This will make both usage auditing and granting permissions much easier to administrate.
0 Likes 0 ·
CirqueDeSQLeil avatar image
CirqueDeSQLeil answered
I agree with many here that SQL is not on its way out. SQL will be around for a long time in one fashion or another.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.