the sql delete query is used to delete the existing records from a table.
you can use the where clause with a delete query to delete the selected rows, otherwise all the records would be deleted.
syntax
the basic syntax of the delete query with the where clause is as follows −
delete from table_name where [condition];
you can combine n number of conditions using and or or operators.
example
consider the customers table having the following records −
+----+----------+-----+-----------+----------+ | id | name | age | address | salary | +----+----------+-----+-----------+----------+ | 1 | ramesh | 32 | ahmedabad | 2000.00 | | 2 | khilan | 25 | delhi | 1500.00 | | 3 | kaushik | 23 | kota | 2000.00 | | 4 | chaitali | 25 | mumbai | 6500.00 | | 5 | hardik | 27 | bhopal | 8500.00 | | 6 | komal | 22 | mp | 4500.00 | | 7 | muffy | 24 | indore | 10000.00 | +----+----------+-----+-----------+----------+
the following code has a query, which will delete a customer, whose id is 6.
sql> delete from customers where id = 6;
now, the customers table would have the following records.
+----+----------+-----+-----------+----------+ | id | name | age | address | salary | +----+----------+-----+-----------+----------+ | 1 | ramesh | 32 | ahmedabad | 2000.00 | | 2 | khilan | 25 | delhi | 1500.00 | | 3 | kaushik | 23 | kota | 2000.00 | | 4 | chaitali | 25 | mumbai | 6500.00 | | 5 | hardik | 27 | bhopal | 8500.00 | | 7 | muffy | 24 | indore | 10000.00 | +----+----------+-----+-----------+----------+
if you want to delete all the records from the customers table, you do not need to use the where clause and the delete query would be as follows −
sql> delete from customers;
now, the customers table would not have any record.