DELETE Command in SQL

For Complete YouTube Video: Click Here

In this class, we will understand the DELETE Command in SQL.

We have already discussed the concepts of the Update command.

DELETE Command in SQL

DELETE is a Data Manipulation Language DML command.

The DELETE statement is used to delete existing records in a table.

DELETE Command syntax in SQL

The syntax for the delete command in the SQL is as shown below.

DELETE Command in SQL 1
DELETE Command in SQL 1

DELETE FROM table_name WHERE condition;

DELETE FROM is the keyword.

After the DELETE FROM, we have to provide the table name where the deletions are.

Next, we have to provide the WHERE condition.

We will try to understand the concept by using the table given below.

In the above table, we will try to delete the students whose salary is 100.

The command for the deletion is as shown below.

DELETE FROM students WHERE salary = 100;

As we have discussed, the SQL will execute row by row.

In our case, the first row will get executed as the salary of the student Vikram is 100.

The image below is the output of the query.

DELETE Command in SQL 2
DELETE Command in SQL 2

DELETE without WHERE clause

It is important to check the WHERE clause because if we forget to give the where clause, all the rows in the table will get deleted. 

This kind of deletion may produce a disastrous effect.

For example, consider the query without the where clause as shown below.

DELETE FROM students;

The image below is the output of the query.

DELETE Command in SQL 3
DELETE Command in SQL 3

All the remaining 4 rows will get deleted.