Later, you will learn how to put the DELETE statement in a transaction so that you can roll it back. Note that once you delete data, it is gone. We will use the employees table in the sample database for the demonstration. To delete all rows in a table without the need of knowing how many rows deleted, you should use the TRUNCATE TABLE statement to get better performance.įor a table that has a foreign key constraint, when you delete rows from the parent table, the rows in the child table will be deleted automatically by using the ON DELETE CASCADE option. To delete data from multiple tables using a single DELETE statement, you use the DELETE JOIN statement which will be covered in the next tutorial. ![]() ![]() If you omit the WHERE clause, the DELETE statement will delete all rows in the table.īesides deleting data from a table, the DELETE statement returns the number of deleted rows. Notice that the WHERE clause is optional. The DELETE statement will delete rows that match the condition, Second, use a condition to specify which rows to delete in the WHERE clause.First, specify the table from which you delete data.WHERE condition Code language: SQL (Structured Query Language) ( sql ) To delete data from a table, you use the MySQL DELETE statement. The following illustrates the syntax of the DELETE statement: DELETE FROM table_name Summary: in this tutorial, you will learn how to use the MySQL DELETE statement to delete data from a single table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |