Database Basics

What is the result of executing DELETE FROM employee in SQL without a WHERE clause?

  1. AAll rows of the employee table are deleted, and an empty table remains
  2. BThe table itself is deleted, and its definition is gone too
  3. 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.
Practice this topic Back to topic

Related calculators

Books on Database Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Database Basics questions

  1. The score column of an exam table contains four values: 80, NULL, 70, 90 (NULL means the person did not take the exam). What is the result of SELECT AVG(score) FROM exam?
  2. The score column of a result table contains six values: 50, NULL, 70, NULL, 90, 30. Which shows, in order, the result of SELECT COUNT(*), COUNT(score), AVG(score) FROM result?
  3. From an employee table (emp_no, dept, salary), you want the departments whose average salary is 300 or more, together with that average. Which SQL statement is correct?
  4. A sales table (store, amount) has seven rows: (A, 500), (A, 700), (B, 300), (B, 400), (C, 1200), (D, 200), (D, 900). How many rows does SELECT store, SUM(amount) FROM sales GROUP BY store HAVING SUM(amount) >= 1000 return?
  5. An employee table (name, dept, salary) has eight rows, with salaries by department as follows: Sales 320, 280, 350; Dev 400, 310; Admin 260, 300; Planning 330. How many rows does SELECT dept, COUNT(*) FROM employee WHERE salary >= 300 GROUP BY dept HAVING COUNT(*) >= 2 return?