Database Basics
What is the result of executing DELETE FROM employee in SQL without a WHERE clause?
- AAll rows of the employee table are deleted, and an empty table remains
- BThe table itself is deleted, and its definition is gone too
- CBecause there is no WHERE clause, an error occurs and nothing is deleted
Show answer and explanation
Answer: A. All rows of the employee table are deleted, and an empty table remains
DELETE is a DML statement that removes rows from a table. With a condition in a WHERE clause, only the rows that meet it are deleted; if the WHERE clause is omitted, every row is deleted. Even after DELETE removes all rows, the table definition (column names, types and constraints) remains, so rows can be added again with INSERT. Deleting the table itself, definition included, is done with the DDL statement DROP TABLE employee. The same applies to UPDATE: forgetting the WHERE clause rewrites every row, so it is important to check the condition before running it. Inside a transaction, the change can be cancelled with ROLLBACK before COMMIT.
- A. Correct. All rows are deleted, but the table definition remains.
- B. Deleting the table along with its definition is DROP TABLE. DELETE removes only rows.
- C. The WHERE clause may be omitted, in which case every row is affected.