SQL is a Declarative Language

Join over 2 million students who advanced their careers with 365 Data Science. Learn from instructors who have worked at Meta, Spotify, Google, IKEA, Netflix, and Coca-Cola and master Python, SQL, Excel, machine learning, data analysis, AI fundamentals, and more.

Start for Free
Martin Ganchev 25 Apr 2023 5 min read

If SQL seems a bit more different to you than C++, for example, this is because SQL is a declarative language. Understanding how SQL fits the whole picture will be much easier if you know what databases are all about. SQL is just the programming language you need to execute commands that let you create and manipulate a relational database.

Which Are the Different Types of Programming?

We will not delve into strict and detailed technical definitions to explain how it works. What you need to know is that there are a few types of programming out there – procedural (imperative), object-oriented, declarative, and functional.

Types of programming, procedural object oriented, declarative, functional

Although it has some procedural elements, SQL is a declarative language - it is nonprocedural. This means, while coding, you will not be interested in how you want the job done. The focus is on what result you want to obtain.

SQl is declaritive

A Procedural vs a Declarative Language

An abstract example would best clarify what the difference is between using a procedural and a declarative language.

The Way to Solve Tasks using C or Java

When using a procedural language, such as C or Java, we must explicitly divide the solution of a certain problem into several steps. For instance, if we wanted to tell the machine to bring us a bucket, in Java we would have to turn the following steps into code:

  1. Please, open the door.

imperative process of getting a bucket, sql is a declarative language

  1. Go outside.
  2. Pick up the bucket I left there.
  3. Bring it back to me.

The Way to Solve Tasks Using SQL In a declarative language, the same task would sound like:

  1. Fetch the bucket, please.

And you wouldn’t have to go through the process step by step. The algorithms are built-in, and there is an optimizer, which will separate your task into smaller steps and do the magic to bring the desired output.

4 items describing how to get the bucket and one on what the process is, sql is a declarative language

This is important because when using SQL, you should concentrate on what you want to retrieve from your database. Unless you are an advanced user, don’t bother with the algorithms explaining how your data can be obtained.

What is the most important part

How to Work With SQL

To sum up, SQL and Java have nothing in common when it comes to the way you go about solving tasks. Now you know that you should be focused on what you want to do rather than how to do it. If you want to expand your knowledge even more, don’t think twice before diving into the concept of relational databases.

***

Eager to hone your SQL skills? Enroll in our SQL course.

Next Tutorial: Relational Databases

Martin Ganchev

Instructor at 365 Data Science

Martin holds an MSc degree in Economic and Social Sciences from Bocconi University. His diverse academic and research experience combined with his friendly and explanatory approach to teaching have made him one of the most beloved instructors on our team. Some of the courses he has authored include: SQL, SQL + Tableau, SQL+Tableau+Python, Introduction to Python, Introduction to Jupyter, to name a few.

Top