×

DML Commands in SQL

DML is an abbreviation of Data Manipulation Language.

Data Manipulation Language commands in Structured Query Language manipulate the data in the database. DML commands are used to retrieve records, add records, update the records, as well as remove the data from the existing table.

The SQL commands fall under the DML commands is as follows:

  1. SELECT Command.
  2. INSERT Command.
  3. UPDATE Command.
  4. DELETE Command.

1. INSERT DML Command

INSERT is a DML command in the SQL. The INSERT command is used to add a new record to the table.

The syntax of the INSERT command is as follows:

INSERT INTO TABLE_NAME VALUES (Data_1, Data_2, Data_3, Data_4);

The above syntax adds records in all the table fields without mentioning the field name, but the column sequence must be correct.

INSERT INTO TABLE_NAME (COLUMN_NAME1, COLUMN_NAME2) VALUES (Data_1, Data_2);

The above Syntax is used to add records for the selected columns of the table.

Examples of INSERT Command

Example 1: The below example adds a record to the table

Consider the newly created table name stud, which has no data.

We will execute the INSERT command to add data to the stud table

INSERT INTO STUD VALUES (1, ‘Shivani Agrawal’, 15, ‘Mumbai’, 85, 9);

The above query adds a single record to the table. We can insert multiple values into the tables, taking multiple value insertion.

Example 2: These examples describe how to INSERT multiple values into the table.

Now we will store multiple new records on the stud table. To store multiple records in a table, we will execute the following Data Manipulation Language INSERT command:

INSERT INTO STUD VALUES (2, 'Pranoti Shende', 16, 'Kohlapur', 95, 9), (3, 'Vaibhav Sharma', 15, 'Noida', 90, 16);

2. SELECT DML Command

The Most important DML command in the SQL is the SELECT Command. We execute the SELECT query to display data from the table.

The Syntax of the SELECT command is as follows:

SELECT * FROM TABLE_NAME;

The above syntax retrieves all the records from the mentioned table name

SELECT COLUMN_NAME_1, COLUMN_NAME_2, COLUMN_NAME_N FROM TABLE_NAME;

The above syntax is used to retrieve records from the mentioned column name

SELECT * FROM TABLE-NAME WHERE COLUMN_NAME;

The above syntax is used to display the specific records from the table

Examples of SELECT Command

Example 1:  This example fetches all the data of each column from the table:

SELECT * FROM STUD;

The output of the above query is as follows:

STUD_IDSTUD_NAMESTUD_AGESTUD_CITYSTUD_MARKS
1Shivani Agrawal15Mumbai85
2Pranoti Shende16Kolhapur95
3Vaibhav Sharma15Noida90
DML Commands in SQL

Example 2:  This example fetches all the data of the selected column from the table:

SELECT STUD_ID, STUD_NAME, STUD_AGE FROM STUD;

The above query retrieves records from the selected columns

The output of the above query is as follows:

STUD_IDSTUD_NAMESTUD_AGE
1Shivani Agrawal15
2Pranoti Shende16
3Vaibhav Sharma15
DML Commands in SQL

Example 3:  These examples fetch a single row of all data using the WHERE clause specified by column name from the table:

SELECT * FROM STUD WHERE STUD_ID = 1;

The above query retrieves records of student information whose student id is 1.

The output of the above query is as follows:

STUD_IDSTUD_NAMESTUD_AGESTUD_CITYSTUD_MARKS
1Shivani Agrawal15Mumbai85
DML Commands in SQL

3. UPDATE Data Manipulation Language Command

UPDATE Command is a DML Command in the SQL. The UPDATE commands are     used to update the existing records in the table.

The syntax of the UPDATE command is as follows:

UPDATE TABLE_NAME SET COLUMN_NAME1 = VALUES, COLUMN_NAME2 = VALUES WHERE CONDITION;

The SET keyword is used to update the column in the above syntax

Examples of UPDATE Command

Example 1: The below example helps you with how the UPDATE query works:

Consider the already existing table with the following data

Table Name: Stud

STUD_IDSTUD_NAMESTUD_AGESTUD_CITYSTUD_MARKS
1Shivani Agrawal15Mumbai85
2Pranoti Shende16Kolhapur95
3Vaibhav Sharma15Noida90

I want to modify the student city whose student id is 3. To update records, we will execute the following Data Manipulation Language UPDATE command:

UPDATE STUD SET STUD_CITY = ‘PUNE’ WHERE STUD_ID = 3;

We will execute the SELECT query to verify whether the student information is successfully updated or not

UPDATE STUD SET STUD_CITY = ‘PUNE’ WHERE STUD_ID = 3;

The output of the above query is as follows:

STUD_IDSTUD_NAMESTUD_AGESTUD_CITYSTUD_MARKS
3Vaibhav Sharma15Pune90
DML Commands in SQL

Example 2: The below example describes how to modify the multiple values.

We need to modify the student marks and student age whose student city is ‘Pune’. To update records, we will execute the following Data Manipulation Language UPDATE command:

UPDATE STUD SET STUD_MARKS = 93, STUD_AGE = 16 WHERE STUD_CITY = 'PUNE';

We will execute the SELECT query to verify whether the student information is successfully updated or not

SELECT * FROM STUD WHERE STUD_CITY = ‘PUNE’; 

The output of the above query is as follows:

STUD_IDSTUD_NAMESTUD_AGESTUD_CITYSTUD_MARKS
3Vaibhav Sharma16Pune93
DML Commands in SQL

4. DELETE DML Command

The DELETE command is a DML command that removes the data from the existing table. The WHERE clause conditions are used in the queries to remove data from the table.

The syntax of the DELETE command is as follows:

DELETE FROM TABLE_NAME WHERE CONDITION;

Examples of DELETE Command

Example 1: The below example describes how to remove the records from the existing table.

Consider the already existing table with the following data

Table Name: Stud

STUD_IDSTUD_NAMESTUD_AGESTUD_CITYSTUD_MARKS
1Shivani Agrawal15Mumbai85
2Pranoti Shende16Kolhapur95
3Vaibhav Sharma16Pune93

For example, we want to delete the records from the stud table whose city name is 'Mumbai'. To remove records, we will execute the following Data Manipulation Language DELETE command:

DELETE FROM STUD WHERE STUD_CITY = ‘MUMBAI’;

We will execute the SELECT query to verify whether the student information is successfully deleted or not

SELECT * FROM STUD;

The output of the above query is as follows:

STUD_IDSTUD_NAMESTUD_AGESTUD_CITYSTUD_MARKS
2Pranoti Shende16Kolhapur95
3Vaibhav Sharma16Pune93
DML Commands in SQL

Related Topics

Grant Command in SQL

What is DCL (Data Control Language)? Data Control Language (DCL) is a computer programming language with syntax intended to manage access to data kept in databases. It is a part of...

3 minutes read.

SQL Data Definition Language

Data definition language directly effects on the structure/schema of the database. CREATE, ALTER, DROP are the commands of DDL.CREATE: Creates new database, table, or view of table.ALTER: Modifies the database or...

3 minutes read.

SQL INSERT Statement

In this tutorial, we will help you to understand and learn how to insert records to the table in SQL with the help of examples. SQL INSERT query is used to...

5 minutes read.

SQL Aggregate Operators

In SQL, the aggregate operators perform a calculation on multiple rows or multiple values of a single column and give the output a single value. Here, multiple rows of data are...

4 minutes read.

How to delete column in table

Introduction In SQL, sometimes it is required to delete a column of a table.The use of ALTER TABLE command with DROP COLUMN clause will serve the purpose to delete/remove a column...

4 minutes read.

SQL Cast Operator

While writing SQL queries, we can see many values which are to be converted into another datatype for accessing them. In SQL this conversion is generally done by CAST function. CAST...

4 minutes read.

How to Create Temporary Table in SQL?

How to Create Temporary Table in SQL  Introduction to Temporary Tables Temporary table is a table which is used to store temporary data that can be used further in the same client...

3 minutes read.

Trigger in SQL

In this article, we will learn about the concept of trigger in SQL and its implementation with the help of an example. A Trigger in Structured Query Language is a set...

4 minutes read.

SQL HAVING Clause

In this tutorial, we will understand the HAVING clause concept in SQL with the help of examples. The HAVING Clause in the SQL is used as we cannot use the WHERE...

3 minutes read.

SQL Auto Increment

As we all know, In SQL for unique identification, we assign a column with the primary key. But in some tables, we find difficult to differentiate a column as a...

5 minutes read.

SQL SELECT MAX

The SQL Max() function is an aggregate function in SQL. This function returns the values which are greater in the condition. The condition may be a number, or it may...

5 minutes read.

SQL TABLE

SQL TABLE Structured Query Language (SQL) is a relational database (RDBMS) where data is stored in the form of tables, that is, in rows and columns. These tables are known as...

3 minutes read.

SQL Except

In SQL, we probably use the JOIN clause to receive the combined result from one or more than one table. But sometimes, we want a result that contains data from...

4 minutes read.

SQL Syntax

In this tutorial, we will help you understand about the different SQL Syntax concepts with the help of an example. Every Structured Query Language starts with Keywords like select, insert, update,...

5 minutes read.

SQL Inner Join

In Structured Query Language, the most used join query is the Inner join query. Inner join query retrieves the records from one or more tables with similar data or records. The...

4 minutes read.

SQL Queries

In a database, queries are used to request the result set of data from the table or action on the records. A Query can answer your simple or complicated question, perform...

5 minutes read.

SQL Injection

SQL injection is a technique, this may destroy the database. It is one type of hacking technique. SQL IN WEB PAGES: Injection occurs when we ask for input like an id or...

3 minutes read.

SQL Data Types

In SQL DATA TYPES, each column holds value. Data types can be an integer type, character type, etc., and such data is stored in the database table. The data type is...

4 minutes read.

SQL IN vs SQL EXISTS

SQL IN vs SQL EXISTS This article discusses in detail about the IN and the EXISTS operators in SQL. It is a common question between developers that what is the difference...

3 minutes read.

SQL DROP Table

In this tutorial, we will help you to understand how to delete the table from the database in SQL with the help of examples. The DROP TABLE query is used to...

4 minutes read.