
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DML - Data Manipulation Language
It refers to a language that is used to insert, delete and update data in a database. It is used for the manipulation of data in the database.DCL is used together with DML because the changes made by dml wouldn't be saved permanently and have a chance of rolling back. Here are three DML commands:
Insert into command
It is used to insert a data row in a table.
Syntax
INSERT INTO table_name(col1,col2,col3,..) VALUES (value1,value2,value3,...); or INSERT INTO table_name VALUES (value1,value2,value3,...);
Example
This example will show the use of the insert command in a table. Insert is used to provide the values or entities into the table through the insert statement
Algorithm
Step1: Create a table
Step 2: Insert values into the table using INSERT.
Step3: Select the table to show output and to see the values that get inserted
CREATE TABLE student(id int,name char(50),roll_no. (50),branch char(50);#table created INSERT INTO student(id,name,roll_no,branch) VALUES (1,aman,20,cs), (2,naman,21,civil), (3,raman,22,bao);#rows are inserted SELECT * FROM student;#table selected to show output
Output
id name roll_no. branch 1 aman 20 cs 2 naman 21 civil 3 raman 22 bao
Update Command
It is used to update existing data in a table of a database. It can be used to update single or multiple columns at a time as per the requirement.
Syntax
UPDATE table_name SET values_to_update(1_col=1_value,2_col=2_value,....) WHERE condition;
Here,
table_name is the name of the table
1_col,2_col... are the column
1_value,2_value...are the updated value for columns
conditions are there to select the row on which the value will get updated.
Algorithm
Step1: Use update to update the data
Step2: Provide table name
Step3: Set values to get updated
Step4: Provide condition of where to perform updation
Step5: Select the table to show the output
Example
UPDATE student #update operation is to be performed on student table SET name='monu',roll_no=25#set updated values WHERE id=1;#condition regarding where to update SELECT * FROM student;#Select table to show output
Output
id name roll_no. branch 1 monu 25 cs 2 naman 21 civil 3 raman 22 bao
Delete command
It is used to delete records from a table given. One can delete single or multiple records depending upon the condition provided in the WHERE clause.
Syntax
DELETE FROM table_name WHERE condition;
Here,
table_name is the name of the table
table_name is the name of the table
Example
This example will show how the delete command is used to delete or remove the existing data present in the table.
Algorithm
Step1: Use delete
Step2: Provide table name
Step3: Provide condition of where to perform the deletion
Step4: Select the table to show the output
Input
id name roll_no. branch 1 monu 25 cs 2 naman 21 civil 3 raman 22 bao
Example
DELETE FROM student#table on which data deletion will occur WHERE id=1;# condition regarding where to delete SELECT * FROM student;#Select table to show output
Output
id name roll_no. branch 2 naman 21 civil 3 raman 22 bao
Conclusion
This article explains DML which is a part of SQL statements in which commands such as insert, update, and delete take place. Insert is used to insert a data row in a table. The update is used to update data in a database. Delete is used to delete data from the database.