What are the different types of SQL commands?

This article will describe the different types of SQL commands and their use.

I will show you a step by step overview of different types of SQL commands that we commonly use. So that you will have a very clear understanding of this topic after reading this article.

In general SQL commands are the predefined commands which can be used to retrieve data from the database. The SQL Commands are classified as 4 types which are mentioned in the below diagram.

Different Types of SQL Commands

SQL Commands: Data Query Language

The data query language is that if you have some data in the database and you have some data in the tables and also the tables are connected through primary key and foreign keys then you can send requests to your database to retrieve the data.

These requests are processed within the database and you can expect some results back. That is what you are actually interested in and results are some part of your data in the database.

Data Query Language compares the objects just using one command which is called select command. It can be accompanied by many clauses to compose many queries on a database.

SQL Commands - Data Query Language Sample Query

As you can see in the above diagram select means you can choose some data or maybe some big amount of data from your database and after that the columns that you want to choose from the data.

You must specify the table from which you want to choose the data.

In simple command, it is only one table name in the complex command you can apply several tables here.

You can also see our top 4 SQL Queries interview questions there you can find the different types of SQL commands used for the data query language.

There is an optional part that you can discuss later. Next ends your query with semicolon to conclude your command.

The following is a simple example that you refer to online.

You can check the sample database in the below location. You can even modify this database or you can add tables. Also, you can make entries into the tables.

Let us have a quick look at the entity-relationship model of the online database and look into the online UI database.

SQL Commands Entity Relationship Sample Diagram

The particular scenario is the shopping scenario that we captured.

  • Customers can make orders – Customers can make many orders and orders can be made by one customer.
  • The employee of the company cares about the order. – One employee can care about many orders and vice versa.
  • Shippers care about order delivery logistics – Each order is transported by one shipper and shipper can ship many orders.
  • A supplier can supply the products – A supplier can deliver many products and a product can be supplied by one supplier.
  • Customers order Products – Products can be ordered by many customers and many order details a product can be assigned.

Here you see the online database which is available for you. You can apply query language or manipulation language using different types of SQL Commands here.

SQL Commands Sample Database

On the right-hand side, you can see the tables list and numbers are entries here.

You can have a look at the data if you can just click at the table.

You can see the attributes and entries for the selected table as shown in the above diagram.

SQL Commands: Data Definition Language

DDL is that part of the SQL which defines the data structure of the database. In the initial stage when the databases about to be created.

So it is mainly used to create and restructure the databases. You can see commands like Create table, Alter table and Drop table are the commands of DDL.

Data Manipulation Language

Data Manipulation Language is used to manipulate the already existing data in the database.

It helps the user to retrieve and manipulate the data and it is used to perform the operations like inserting the data into the database through insert command.

Also updating the data through the database through update command and deleting the data in the database through delete command.

Data Control Language

Finally, we have data control language DCL. It is used to control the data in the database.

So these DCL commands are normally used to create objects related to user access and also used to control the distribution of privileges among users.

You see commands are grant and revoke in DCL.

Do you have any queries on SQL commands? or Would you like to share something about this topic?

Please leave your comments in the comment section.

Thank You. Have a great day.

Leave a comment