DEV Community

It's been nearly 50 years. Is SQL outdated?

Judy on November 07, 2023

Objective of database language To clarify this objective, we need to first understand what the database does. When it comes to database, it always...
Collapse
 
franckpachot profile image
Franck Pachot

I see that you dont like the SQL way to query the DB and prefer a procedural approach. Then you should look at the execution plan, not the SQL text. You try to read SQL as an English sentence with action verbs on physical structures. That doesn't work. The SQL code is a description of the expected result using a logical structure, without any hints on how it must be executed. Think of it as the user specification, not the developer implementation.

For example, you cannot guess the execution logic from SQL statement like you did:

SELECT TOP 10 x FROM T ORDER BY x DESC
However, the execution logic corresponding to this statement is to perform the big sorting for all the data first, and then take the top 10, and discard the remaining data.

This is wrong except if T is a table with no index on x which would be a mistake. This SQL only defines the result as the last 10 rows by x. Why do you think it has to read all and eliminate later?