DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • Common Mistakes to Avoid When Writing SQL Code
  • Recover Distributed Transactions in MySQL
  • Recovering an MS SQL Database From Suspect Mode: Step-By-Step Guide
  • Enhancing Database Efficiency With MySQL Views: A Comprehensive Guide and Examples

Trending

  • Behavior-Driven Development (BDD) Framework for Terraform
  • Advanced-Data Processing With AWS Glue
  • Navigating the Digital Frontier: A Journey Through Information Technology Progress
  • RRR Retro and IPL for Rewards and Recognition
  1. DZone
  2. Coding
  3. Languages
  4. SQL Looks Like English Is a Well-Intentioned Error

SQL Looks Like English Is a Well-Intentioned Error

SQL is a language with very strict syntax, and any non-compliant part of a statement will be rejected by the database. Learn more about its advantages here.

By 
Judy Liu user avatar
Judy Liu
·
Dec. 29, 23 · Opinion
Like (2)
Save
Tweet
Share
3.4K Views

Join the DZone community and get the full member experience.

Join For Free

We know that SQL is very similar to English, and simple SQL statements can be read directly as English. Except for SQL, other major programming languages do not have this feature, and even if there are English words in the syntax, they are only used as mnemonics for certain concepts or operations, and what is written is a formal program statement rather than an English sentence. But SQL is different. It will write the entire sentence in a form that conforms to English habits, and also add many unnecessary prepositions, such as FROM being the operation subject of the statement but having to be written in the behind, and after GROUP, an extra BY needs to be written.

Why is this happening? The easy reason to think of is to hope that non-programmers can also use it. Users can write SQL to query data as long as they can read and write English. This is clearly a good intention, but the result is not satisfactory. The vast majority of business personnel only know how to write very simple queries using SQL, and for such queries, there is now powerful BI software that can provide a more convenient and intuitive visual interface to assist, without the need for handwritten statements. This design intention loses its meaning. On the contrary, the vast majority of users that frequently use SQL for calculations are still programmers, and SQL is still a programming language, like or unlike English, it does not have much difference in understanding for programmers, on the contrary, it can bring considerable difficulties.

In fact, SQL is a language with very strict syntax, and any non-compliant part of a statement will be rejected by the database. Users must study and follow its syntax rules carefully, which is no different from other programming languages. The true advantage of natural language lies in its ambiguity, which allows it to accept less strict syntax to a certain extent. However, SQL does not support this feature, and it was not possible to achieve this feature in the era when SQL was invented.

The benefits of looking like English cannot be reflected, but there are many drawbacks. Designing grammar like natural language may seem easy to master, but in fact, the opposite is true.

The main downside of being like natural language is non-procedural. Program logic is generally executed step by step, using variables to record intermediate results for use in subsequent steps. But natural language is not like this, the citation relationship between two sentences is dependent on a small number of fixed pronouns, which is imprecise and inconvenient. Therefore, it will have to spell actions targeting the same subject into one sentence as much as possible, so there is no need to use pronouns. The corresponding representation in SQL is to have multiple actions in one statement, such as SELECT, WHERE, and GROUP, which were originally unrelated actions. In other programming languages, they are usually designed as multiple functions, but in SQL, they are all designed as clauses of one statement. Moreover, words like “WHERE” and “HAVING” have the same meaning, only targeting different objects, when spelled into one sentence, two words must be used to indicate the difference, which is confusing (many beginners may be confused about HAVING).

Complex situations that cannot be described in a single sentence can be described using clauses in natural language. This is manifested as subqueries in SQL, and there may also be multiple layers of nested subqueries, which is not common in other programming languages. Moreover, subqueries should also be like natural language, with a SELECT…FROM every time, it will make people feel very verbose and the code will become long.

Step-by-step is an effective way to reduce the difficulty of understanding and executing: something that is originally quite simple to do in a few steps, but if you don’t take them step by step, it will be very complicated to implement. It can be imagined that if the teacher asked elementary school pupils to solve practical problems only in one equation, the children would be very distressed (of course, some smart children can handle it).

For example, if we want to find customers whose sales exceed twice the average, the natural way of thinking is to first calculate the average sales, and then find customers whose sales exceed twice this value, implementing with two statements. The writing of SQL requires using subqueries to write one longer sentence. This example is relatively easy to understand, with only two layers. The difficulty of using natural language clauses to describe the relationship within two layers is generally acceptable, but in reality, complex queries involving three or five layers are common, which seriously increases the difficulty of understanding.

Not advocating for step-by-step can lead to a long single SQL statement. The complex SQL statements faced by programmers are rarely counted in lines, often in Ks. However, for the same 100 lines of code, whether it is divided into 100 statements or only 1 statement, its complexity is not at the same level at all. This type of code is very difficult to understand, and once it was finally written, after two months, the programmer himself couldn’t understand it. Moreover, the single long statement without steps is difficult to debug, and the development cycle is also longer.

About procedurality: there is a saying in the industry that SQL is a declarative language, and users only need to care about what they want without caring about how to do it; the database will automatically find a solution, and this language does not need to support procedurality. We have already criticized this statement earlier.

Database vendors may have also seen the lack of procedurality of SQL, so they later added CTE syntax to compensate, which is equivalent to providing intermediate variables that can be named. Stored procedures are also equivalent to being able to execute SQL in steps, with branching loops and even subroutines. The result is still to return to the old path of procedural language, so this is not as good as designing it like this from the beginning.

For programming languages, the ease of use brought by a good step-by-step computing mechanism far exceeds what looks like natural language.

Database sql Syntax (programming languages)

Published at DZone with permission of Judy Liu. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Common Mistakes to Avoid When Writing SQL Code
  • Recover Distributed Transactions in MySQL
  • Recovering an MS SQL Database From Suspect Mode: Step-By-Step Guide
  • Enhancing Database Efficiency With MySQL Views: A Comprehensive Guide and Examples

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: