The basic syntax of a DELETE query is:
DELETE FROM table_name
WHERE condition;
table_name: The name of the table from which you want to delete records.WHERE: Specifies the condition that determines which rows to delete. Without a WHERE clause, all rows in the table will be deleted.Let’s assume we have a table employees and we want to delete the record of an employee with a specific employee_id. Here’s the query:
DELETE FROM employees
WHERE employee_id = 101;
In this example:
DELETE statement removes the row from the employees table.WHERE clause specifies that only the employee with employee_id = 101 should be deleted.DELETE query is used to remove rows from a table.WHERE clause to specify which rows to delete, otherwise, all rows will be deleted.The DELETE query in MySQL is a powerful tool for removing records, but it should be used with caution. Always include a WHERE clause to avoid deleting all rows in a table. Understanding how to use the DELETE query properly ensures safe and effective data management.