SQL Delete table example – Learn how to Delete data from a table in MySQL database with example and important points.
SQL delete statement used to delete a single record or multiple records from the database tables.
SQL syntax for deleting records from database table.
Syntax:
Delete from table_name where <condition>;
SQL query to delete all records from the BOOKS table
Query example: Delete from books;
BY using above query, you can delete all the records from the BOOKS table.
SQL query to delete a single record from database table
Query example: Delete from books where ISBN_NO= 209;
By using above query, we can delete a record with ISBN_NO= 209;
Result set after deleting a single record from the BOOKS table.
Query example: select * from books;
Output:
ISBN_NO | TITLE | AUTHORFIRSTNAME | AUTHORLASTNAME |
---|---|---|---|
181 | The Castle | Franz | Kalka |
191 | Animal Farm | George | Orwell |
205 | Madhushala | Harivansh | Rai |
Points to notice:
- The where clause specifies which records that should be deleted from the database table.
- Without where clause all the records in the database table will be deleted.
- By using delete command we can delete all the records without getting damage to database tables structure.