Is SQL a programming language? 3 key considerations

SQL is a domain-specific programming language that uses queries to manage data in relational databases. 56.9% of developers report using SQL on a professional basis which makes it the third most popular language behind JavaScript, and HTML/CSS. The top four database technologies MySQL, PostgreSQL, Microsoft SQL Server, SQLite, are also all built upon SQL.

Over time SQL has become the de facto language for querying and manipulating data. It is now the most popular language for working with relational databases. 

Whether SQL is a programming language and meets the various criteria is a hotly contested topic online. Arguments can be made either way regarding SQL’s status as a programming language

Let’s explore what SQL is and then look at the different reasons surrounding its status as a programming language. Then move on to why it doesn’t matter if SQL is a programming language.

What is SQL?

Sql logo

SQL is shorthand for Structured Query Language and is a language used to communicate with relational databases. It was created in 1974 by Donald Chamberlin and Raymond Boyce, then was registered with the  American National Standards Institute in 1986. 

Today it is the most common query language used in the software development world and has been built upon with the release of Microsoft SQL Server, MySQL, and PostgreSQL.

SQL is referred to as a domain-specific programming language because its use is limited in scope, unlike general-purpose programming languages. Other domain-specific programming languages like CSS share the same characteristics as SQL of being very narrow in scope but incredibly useful to the development community. 

You can’t build an app or a web page solely with SQL. However, the entire project would not function without a query language like SQL to talk with the database. Its importance can’t be overstated.

Some basic SQL commands include:

  • SELECT – extracts data from a database
  • UPDATE – updates data in a database
  • DELETE – deletes data from a database
  • INSERT INTO – inserts new data into a database
  • CREATE DATABASE – creates a new database
  • DROP TABLE – deletes a table
  • WHERE – used to filter records
  • GROUP BY – used to aggregate results
  • ORDER BY – sort results by ascending or descending

The order you place these commands is incredibly important. The GROUP BY command should follow the WHERE clause but precede ORDER BY. An example SQL query includes:

SELECT column_a, column_b
FROM table_one
WHERE column_a = 2000
GROUP BY column_a, column_b
ORDER BY column_a;

Is SQL a programming language?

SQL is a domain-specific programming language that is programmers use to manage data in a relational database. It has become the de-facto query language to interface with databases and is the most used query language in the world. With nearly 60% of professional developers using SQL in some manner, it is now the third most popular language behind JS and HTML.

The debate rages on about SQL’s status as a programming language in the purest sense of the word. Some programmers believe the lack of decision logic and looping in basic SQL means it lacks a core tenant of what makes a programming language. However, this is contested by large segments of the developer community.

Either way, SQL is virtually important to modern technology and has proved itself a robust and versatile technology. 

The technical definition of a programming language is any set of rules that converts to machine code to implement algorithms. Does SQL meet this criterion?

Let’s explore some reasons why SQL is considered a programming language and why its detractors believe it isn’t.

1. General-purpose vs domain-specific

Some of SQL’s critics will use its narrow usage as a reason that it shouldn’t be considered a programming language. However, this misses the point. 

There are generally two types of programming languages: general-purpose and domain-specific. General-purpose languages have a greater number of applications and are used to write a wide range of software. Examples include C#, C++, JavaScript, Java, Python, Ruby, and Ruby. In contrast, domain-specific languages are specialized to a specific application or domain. SQL is a query language that is suited to managing databases while HTML is a markup language and is suited to browsers. They both achieve a narrow range of goals incredibly well.

When people argue against SQL as a programming language they often use its narrow use as a reason. However, it’s purpose-built to serve a small range of tasks. 

SQL is not a general-purpose programming language and that is the point. It is used specifically to communicate with relational databases and it performs this task excellently. You can’t write a UI frontend with SQL or build an API but that is entirely the point.

2. No Loops

It’s argued that SQL can’t be a programming language because in its purest form it can’t perform loops or implement decision logic. It is a pretty valid point but has largely been negated by the release of SQL-based languages like PostgreSQL and MySQL. These allow you to create loops and implement logic. 

Some would argue further that these are not dialects of SQL but are their own languages entirely. Whatever your view they both remain SQL compliant and add additional functionality.

3. Turing Complete

Many in the tech world like to define a programming language based on whether it is Turing complete or not. A language is said to be Turning complete when it can be used to simulate any Turing machine and can recognize or determine other data-manipulation rules. It’s based on computer theory work completed by AlanTuring.

SQL with the addition of recursive queries is Turing complete. So it’s another notch on the scoreboard for proving SQL is a programming language.

Is SQL a coding language?

SQL is a coding language because it requires a certain syntax and vocabulary to make it work. However, we can only use SQL when interacting with databases which means it is considered a domain-specific language, rather than a general-purpose language.

There are developers whose primary work revolves around creating, maintaining, and updating SQL databases. However, a lot of the time these developers will know more than one programming language. SQL is useful as a coding language but because of its limited scope, you need to know at least one other language. Try using SQL syntax to do anything but interact with a database and you’ll soon understand its limitations.

Is SQL a programming language or a database?

SQL is not a database, it is the language we use to interact with databases. It is the key we use to unlock the information that is stored in a database. Without SQL and similar languages getting the information we need for databases would not be possible.

There are a few different implementations of SQL as a programming language. Transact-SQL is used by Microsoft SQL Server and there is also PostgreSQL, Oracle SQL, and MySQL. While some of these are open-source, like MySQL, others have commercial licenses and can only be used with specific programs like Oracle SQL.

While all variations of SQL allow you to interact with databases, some of the implementations are more customisable that others.

Does it matter what type of language SQL is?

It doesn’t really matter whether SQL is considered a programming language or not. Its global popularity and widespread usage speak volumes about its effectiveness. Whether it’s considered a ‘real’ programming language or just a query language isn’t as important as the argument surrounding it. 

Often people try to denigrate certain languages to devalue the work of other developers. It’s the reason JavaScript is considered lightweight, and I don’t mean in the technical sense. 

People like to elevate themselves while pushing others down and this is often at the heart of the argument about whether SQL Is a programming language. The question doesn’t often come from a place of good intent. 

We should be looking to respect our colleagues in the tech world. Not draw lines in the sand about what languages are ‘real’ programming languages. It doesn’t matter whether you think Bootstrap is easy to learn or whether a developer should learn Java instead of JavaScript. 

Developers across the world are doing fantastic work in a wide range of programming languages and their work shouldn’t be devalued based on pretty subjective definitions. We shouldn’t use the discussion around programming languages to gatekeep the terms programmer or software engineer. 

The reality is that most successful software engineers get things done, they can outline solutions and approaches regardless of the language. The languages you use daily aren’t the defining metric of how good a developer you are – despite what StackOverflow and Reddit threads may tell you.