The DELETE Command
tags: #sql/basic_statements
The DELETE statement is used to delete existing records in a table.
The this command is part of the DML (Data Manipulation Language)[1] and is used to remove specific rows from a table based on a condition. We can delete all rows or filter which rows to delete by using The WHERE Clause clause.
The number of tuples deleted depends on the number of tuples in the relation that satisfy the WHERE clause.
The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row.
DELETE Syntax
DELETE FROM table_name WHERE condition;
Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted!
Deleting all records
It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:
DELETE FROM tablename;
This SQL statement deletes all rows in the table, without deleting the table.
DML commands are used to interact with the data stored within the database objects (like tables). They affect the rows of a table without changing its structure. DDL commands are used to define or modify the structure of database objects. They operate on the schema, not the data within the tables. ↩︎