Hey there 👋
Hope you are doing well 🙂
In the last blog we have discussed about DDL (Data Definition Language) commands. In this blog we are going to see some of the basic commands of SQL. We will be discussing DML (Data Manipulation Language) commands in this blog.
Data Manipulation Language Commands
Data Manipulation Language (DML) Commands are used to manipulate data present in the database.
Some of the commonly used DML commands are -:
INSERT
UPDATE
DELETE
LOCK
CALL
EXPLAIN PLAIN
In this blog we will be focusing on the above three commands, we will look the last three commands in upcoming blog.
INSERT Command
In the last blog we have seen how to create a table let me explain you again with an example -:
So here we have created a table named Student that contains three variables namely Name (a string of atmost 50 characters), Roll_no (an integer value) and Class (a string of atmost 10 characters).
We will understand table schema in the next blog for now we will try to insert some data in this table.
So we have added three rows in our table. Now our table looks like this -:
So you may have understood that INSERT command is used to insert data in table. It allows for the insertion of data either by specifying the column names along with the values or by providing values for all columns in the table.
So this is one usecase here now suppose we need to insert values of only first two columns how are we going to do that. Let's see-:
So here we have specified the column names in which we want to insert values. Let's have a look on our table now -:
We will see some advanced use cases of this command in coming blogs. For now let's keep it simple.
UPDATE Command
Now suppose we need to update the existing data in the table.
Let's suppose in the above table we need to update the row with Name="Raj"
. So here's how we will do it-:
So here we have updated the table Student. For this we have selected the row with Roll_no 30 and then we set the Name as "Anand".
This is one of the simplest use case of UPDATE command. For advanced use cases we need to understand more commands.
DELETE Command
The DELETE command is used to remove one or more rows from table depending on the condition we imply. Unlike the DROP statement, which removes the entire table, the DELETE statement removes data (rows) from the table retaining only the table structure, constraints, and schema.
In the above table we will remove the last two rows. This is how we will do it -:
As we have not provided any value in Class column in last two rows that is why we have used the condition Class is NULL
as by default CLASS column is initialized by NULL.
So these were three basic DML commands. This was just an introduction we will see some good use cases in upcoming blogs.
In the next blog we will see SELECT statement and its use cases.
I hope you liked my blog. Please leave some ❤ and don't forget to follow me.
Also have you checked my Instagram page where I upload necessary resources for software engineers.
If not check it out here -:
👉 Instagram: https://www.instagram.com/fluxx_96/
👉 YouTube: https://www.youtube.com/@Fluxx-n4q/shorts
Thankyou 💙
Top comments (0)