sql
  1. sql-delete-statement

SQL DELETE Statement

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

Syntax

DELETE FROM table_name WHERE condition;
  • table_name: The name of the table from which you want to delete data.
  • condition: The condition specifies which record or records that should be deleted from the table.

Example

Suppose we have a table named "employees" with the following data:

ID Name Age Salary
1 John Doe 25 5000
2 Jane Doe 30 6000
3 Mark Lee 35 7000

The following SQL query will delete the record with ID = 2 from the employees table:

DELETE FROM employees WHERE ID = 2;

Output

After executing the above SQL query, the employees table will have the following data:

ID Name Age Salary
1 John Doe 25 5000
3 Mark Lee 35 7000

Explanation

In the above example, the DELETE statement is used to delete the record with ID = 2. The WHERE clause specifies the condition that needs to be satisfied in order to delete a record from the employees table.

Use

  • To delete unneeded or redundant data from a database.
  • To remove specific records from a table based on some condition.

Important Points

  • The DELETE statement removes only the data of the table, not the table itself.
  • Always use caution when using DELETE statement as it can delete all the data from your table if not used correctly.

Summary

The SQL DELETE statement is used to delete records from a table that satisfy a specific condition. It is important to use DELETE statement with caution as it can delete all the data from your table if not used properly.

Published on: