In this article we will see the different types of SQL commands and its use.
Let us see the step by step overview of different types of SQL commands that we commonly use. After reading this article you will have a very clear understanding on this topic.
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.
SQL Commands: Data Query Language (DQL)
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.
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.
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 based on your requirement.
Let us have a quick look at the entity-relationship model of the online database and look into the online UI database.
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.
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)
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 (DML)
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 (DCL)
Finally, we have data control language. 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 Data Control Language.
This is all about SQL Commands. I hope this article is useful to you. Please leave your comments in the comment section.