You can use the DELETE statement to remove rows from a table.
Examples
The following example shows how all employees in department 20 are deleted.
In the sample database, query all departments and employees in emp. For more information about the sample database, see A sample database.
SELECT ename, deptno FROM emp;
The following result is returned:
ename | deptno --------+-------- SMITH | 20 ALLEN | 30 WARD | 30 JONES | 20 MARTIN | 30 BLAKE | 30 CLARK | 10 SCOTT | 20 KING | 10 TURNER | 30 ADAMS | 20 JAMES | 30 FORD | 20 MILLER | 10 (14 rows)
Delete all employees in department 20.
DELETE FROM emp WHERE deptno = 20;
Query the departments and employees after the delete operation.
SELECT ename, deptno FROM emp;
The following result is returned:
ename | deptno --------+-------- ALLEN | 30 WARD | 30 MARTIN | 30 BLAKE | 30 CLARK | 10 KING | 10 TURNER | 30 JAMES | 30 MILLER | 10 (9 rows)
Be cautious when you execute a DELETE statement without a WHERE clause. The following example shows this type of statement:
DELETE FROM tablename;
This statement removes all rows from the specified table and leaves the table empty. The system does not request confirmation before this deletion.