Header Ads Widget

SQL DELETE Statement

SQL DELETE Statement

The SQL DELETE statement is used to delete rows from a table. Generally, DELETE statement removes one or more records form a table.

Syntax

  1. DELETE FROM table_name WHERE some_condition;  

Sample Table

EMPLOYEE

EMP_IDEMP_NAMECITYSALARYAGE
1AngelinaChicago20000030
2RobertAustin30000026
3ChristianDenver10000042
4KristenWashington50000029
5RussellLos angels20000036
6MarryCanada60000048

Deleting Single Record

Delete the row from the table EMPLOYEE where EMP_NAME = 'Kristen'. This will delete only the fourth row.

Query

  1. DELETE FROM EMPLOYEE   
  2. WHERE EMP_NAME = 'Kristen';  

Output: After executing this query, the EMPLOYEE table will look like:

EMP_IDEMP_NAMECITYSALARYAGE
1AngelinaChicago20000030
2RobertAustin30000026
3ChristianDenver10000042
5RussellLos angels20000036
6MarryCanada60000048

Deleting Multiple Record

Delete the row from the EMPLOYEE table where AGE is 30. This will delete two rows(first and third row).

Query

  1. DELETE FROM EMPLOYEE WHERE AGE30;  

Output: After executing this query, the EMPLOYEE table will look like:

EMP_IDEMP_NAMECITYSALARYAGE
2RobertAustin30000026
3ChristianDenver10000042
5RussellLos angels20000036
6MarryCanada60000048

Delete all of the records

Delete all the row from the EMPLOYEE table. After this, no records left to display. The EMPLOYEE table will become empty.

Syntax

  1. DELETE * FROM table_name;    
  2. or  
  3. DELETE FROM table_name;  

Query

  1. DELETE FROM EMPLOYEE;  

Output: After executing this query, the EMPLOYEE table will look like:

EMP_IDEMP_NAMECITYSALARYAGE

Note: Using the condition in the WHERE clause, we can delete single as well as multiple records. If you want to delete all the records from the table, then you don't need to use the WHERE clause.

Post a Comment

0 Comments