SQL DELETE Query

The SQL DELETE clause is used to delete existing records in a table permanently.

DELETE Query Syntax

DELETE FROM table_name
WHERE condition;

DELETE FROM table_name; //It delete all record(s) in a table//

Employee Table

A sample of EMPLOYEE records table & the name of table Employee. The column(s) of the Employee table [ID, EMPLOYEE_NAME, EMPLOYEE_EMAIL, ADDRESS, CITY, and COUNTRY]:

ID EMPLOYEE_NAME EMPLOYEE_EMAIL ADDRESS CITY COUNTRY
1 Mark J. mark@gmail.com House 53, Sq. London U.K.
2 Lack Josh lackjosh@gmail.com 2745 road mark Delhi India
3 Kim Juhu kimjuhu@gmail.com Street 587327, 34 House Seoul South Korea
4 Jack Jenifer jenifer@gmail.com 464673 Mataderos Mexico D.F. Mexico
5 McKinley mckinley@gmail.com 54, Road Washington Washington U.S.
6 Alena aln@gmail.com House No. 6563 Tokyo Japan Japan
7 Mack Marina mmk@gmail.com 43 Road, NH San Francisco U.S.
8 Dipak Jha jha@gmail.com Mahanager, 26 Road Lucknow India

DELETE Query [WHERE clause]

DELETE FROM Employee
WHERE ID = 1;

Result Look Like

ID EMPLOYEE_NAME EMPLOYEE_EMAIL ADDRESS CITY COUNTRY
2 Minakshi Kapoor minakshi@gmail.com 2745 road mark Delhi India
3 Kim Juhu kimjuhu@gmail.com Street 587327, 34 House Seoul South Korea
4 Jack Jenifer jenifer@gmail.com 464673 Mataderos Mexico D.F. Mexico
5 McKinley mckinley@gmail.com 54, Road Washington Washington U.S.
6 Alena aln@gmail.com House No. 6563 Tokyo Japan Japan
7 Mack Marina mmk@gmail.com 43 Road, NH San Francisco U.S.
8 Dipak Jha jha@gmail.com Mahanager, 26 Road Lucknow India

DELETE Query without [WHERE]

DELETE FROM Employee;

Result Look Like

ID EMPLOYEE_NAME EMPLOYEE_EMAIL ADDRESS CITY COUNTRY

Important Descriptions

  • If WHERE clause is not use in DELETE query; you might loss all the rows from a table; that's why you should need to use WHERE condition if you want to delete a specific record.
  • In the upper query deleted all records in a Employee table BUT the Employee table still visible.
  • The WHERE clause is optional.
  • Actually, WHERE clause is used to identifies the rows in the table that gets deteled.

Policy

GDATAMART.COM is optimized for learning & job information; The users try to improve your knowledge and practical experience through this site but we cannot warrant full correctness of all content... Learn More → | Sitemap →

© 2020 GDATAMART | All Rights Reserved