Why SQL is a set language and not a programming language

SQL stands for Structured Query Language that works on a set of data. A set can consist of a single record or multiple records.

SQL is called a language because it has syntax (the set of rules that defines the combinations of symbols that are considered to be a correctly structured document or fragment in that language.) as well as semantics (the meaning of the formed sentence).

SQL is called a set language and not a programming language because in SQL we only tell the system what we want and the system decides the how to part itself. But in a programming language, we mention what and how to part ourselves.

Let us take an example:

In MySQL, we only tell the system that we want all the records from the employee table where the first name is John. The MySQL system decides itself that how to retrieve that information. It decides that should I scan the whole table or use another method, with the help of available statistics and optimizer.

Now take a real world example to understand the programming language part.

If I need to code a: get Juice bottle from refrigerator. I will provide both the what and how to in one place.

1. Open the refrigerator.
2. Check if there is any Juice bottle in the refrigerator.
3. If yes, then take out one Juice bottle.
4. Close the refrigerator.

Apart from that it lacks features like to be able to perform repetitive tasks (called loops) and decision logic (control structures) that exists in programming language.

But many vendors provide programming language extension to SQL like PL/SQL by Oracle and T-SQL by Microsoft.

Comments

Back To Top

Popular posts from this blog

error 18 at 0 depth lookup: self signed certificate

How to check fragmentation in MySQL tables

How to Drop or Remove or Decommission a Database in Oracle