SQL DELETE Statement

SQL DELETE Statement

SQL DELETE Statement

The SQL DELETE statement is used to remove one or more records from a table. The syntax of the DELETE statement is as follows:

				
					DELETE FROM table_name
WHERE condition;

				
			

Here, table_name is the name of the table that you want to delete records from. The WHERE clause is used to specify the condition that must be met for the records to be deleted. If you omit the WHERE clause, all records in the table will be deleted.

Examples:

    1.Delete the customer with id 102 from the customers table

				
					DELETE FROM customers
WHERE id = 102;

				
			

In this example, the customer with id 102 is deleted from the customers table.

  1. Delete all orders that have a status of ‘cancelled’ from the orders table.
				
					DELETE FROM orders
WHERE status = 'cancelled';

				
			

In this example, all orders that have a status of ‘cancelled’ are deleted from the orders table.

By using the DELETE statement, you can remove unwanted data from your database. It is important to be careful when using the DELETE statement, as it can delete a large number of records if you don’t specify the WHERE clause correctly. You should always make a backup of your data before deleting any records from your database.

Join To Get Our Newsletter
Spread the love