Unveiling SQL
Learn about the declarative nature of SQL.
We'll cover the following
Focus on “What,” not “How”
Declarative programming is a programming paradigm that focuses on describing what should be done, rather than how it should be done. In declarative programming, we specify the desired outcome or result, and the underlying system automatically figures out the steps and processes needed to achieve that result. This is in contrast to imperative programming, seen in languages like Python, Java, and C++, where we explicitly specify step-by-step instructions on how to achieve a particular goal.
SQL is a prime example of a declarative programming language. In SQL, we describe the data we want to retrieve, update, or manipulate, and the system takes care of how to retrieve or modify the data efficiently. To get the desired results, a user needs to properly state the requirements in SQL.
An SQL query usually consists of the following three fundamental questions or clauses arranged in the given order:
What are the fields/attributes we want to show in our result set?
What are the data sources?
What criteria/conditions are to be met for those results?
Our task involves employing SQL to precisely define the requirements in terms of these questions, and the system takes care of the rest. While the first two clauses are mandatory, the third one is optional. Every SQL query essentially revolves around these three clauses.
SQL is characterized by its English-like syntax and inherent simplicity, featuring relatively small English-like keywords for executing different tasks. In most cases, the keyword itself conveys its purpose, making its use intuitively understandable.
Let’s see if we can use this knowledge and guess the proper SQL keywords related to these three questions.
What are the fields/attributes we want to show in our result set?
WHERE
What are the data sources?
SELECT
What criteria/condition is to be met for those results?
FROM
Note: The term
WHERE
might imply that it pertains to the data source. However, in SQL, its function is to define the filtering criteria.
As demonstrated in this exercise, the choice of names for the keywords clearly facilitates the association and recollection of their intended usage. This highlights the elegance of SQL.
FAQ
Is it necessary to use uppercase for SQL keywords?