What is SQL?

In order to handle a large volume of data we use some Database Management System and this Database Management System, the most popular DBMS is the Relational Database Management System that stores the data in the form of tables containing rows and columns. The question that arises here is that how data is being stored in the database? You might be using some programming language like Java or Kotlin to develop your application, but in order to store the data in the database, you need some kind of interface or language that will help in the communication between the user and the database. For example, if you know English and you want to communicate with someone that knows French only. So, in order to have communication between you and that guy, you need some kind of interpreter in between that will convert English to french and vice-versa. Similarly, SQL is used to have communication between the user and the database. In this blog, we will learn about SQL. So, let's get started.

SQL

SQL or Structured Query Language is simply a computer language that is used to establish a communication between the user and the database i.e. all the database related operations are performed using this Structured Query Language.

As the name suggests, SQL is used to manage the structured databases like RDBMS. Non-Structured databases can't be managed by SQL. Some of the Relational Database Management Systems like Oracle, MS Access, MySQL, etc uses SQL for all the operations on the database.

Some of the operations that can be performed with the help of SQL are:

  • Users can create a database.
  • Users can create some tables in some database.
  • Users can delete or alter the properties of the table.
  • Users can provide particular grant access to some particular users using the SQL.
  • Users can put constraints on the data stored in the database.

These are some of the operations that can be performed on database with the help of SQL.

In SQL, we give some commands to the system to perform some operation. That command or the instruction is known as a Query. The system will take this query as an input and will give the desired output. So, there are some steps that are included in this whole process. So, let's look at the process involved in executing a SQL query.

Query Processing

In SQL, we write queries to perform certain operations. But those queries are in some high-level language and this high-level language must be converted to some low-level language because the system can understand the low-level languages only. So, following is the block diagram of Query processing in SQL:

Following is the description of the same:

  • SQL Query: It is the query that you are want to execute to get some data from the database. It can be some create table query or delete table query or something else that you want to perform on the database.
  • Parser and Translator: The SQL query is in high-level language and we need to convert this high-level language in low-level language. So, a translator translates the SQL queries into some relational algebraic expressions. At the same time, the Parser checks for some syntax error(if any) and the relations that are used in the RDBMS.
  • Query Optimizer: There can be a number of ways for writing the same query. But your query should be such that it should be the most efficient query. So, the Query Optimizer optimizes the query in such a way that it is the efficient query that can be executed.
  • Query Evaluation: Finally the optimized query will be evaluated and the result will be shown to the users.

Advantages of using SQL

Some of the advantages of using SQL are:

  • SQL is easy to learn and use as compared to the programming languages that we use in our day-to-day life.
  • SQL is efficient.
  • Most of the Relational Database Management Systems use SQL for their database operations.
  • Data integrity can be performed with the help of SQL.

Types of SQL statements

There are various types of SQL statements that are used for various different processes. These are:

  • DDL
  • DML
  • DCL
  • TCL
  • Data Retrieval
DDL - Data Definition Language

Data Definition Language or DDL is used to define the database structure or schema. Some of the DDL commands are CREATE , ALTER , DROP , TRUNCATE , RENAME , COMMENT .

DML - Data Manipulation Language

Data Manipulation Language or DML is used to manage the data within some schema objects like inserting some data in the table or deleting some value from the table. Some of the DML commands are INSERT , UPDATE , DELETE , MERGE .

DCL - Data Control Language

Data Control Language or DCL is used to grant and remove access of schema objects to some users. Some of the DCL commands are GRANT , REVOKE .

TCL - Transaction Control Language

Transaction Control Language or TCL is used to manage the changes that are made by the DML commands. So, the changes made by the DML commands can be controlled by the DCL statements. Some of the DCL commands are COMMIT , ROLLBACK , SAVEPOINT .

Data Retrieval

Data Retrieval is used to retrieve or get data from the database. The SELECT statement is used to retrieve data from the database.

These are some of the statements that are used in SQL for performing various operations. We will learn more about these statements in some other blog in detail.

That's it for this blog. Hope you learned something new today.

Do share this blog with your friends to spread the knowledge. Visit our YouTube channel for more content. You can read more blogs from here .

Keep Learning :)

Team AfterAcademy!