Deleting rows from a table in SQL Which command correctly removes one or more rows from the table named CUSTOMER while allowing you to filter which rows are affected?
-
AREMOVE FROM CUSTOMER ...
-
BDROP FROM CUSTOMER ...
-
CDELETE FROM CUSTOMER WHERE ...
-
DUPDATE FROM CUSTOMER ...
-
ETRUNCATE CUSTOMER WHERE ...
Answer
Correct Answer: DELETE FROM CUSTOMER WHERE ...
Explanation
Introduction / Context:SQL provides specific statements for distinct tasks: creating structures, modifying data, and dropping objects. Deleting rows is a data manipulation task and must be expressed with the correct DML statement so that the DBMS can enforce constraints, log changes, and maintain transactional integrity.
Given Data / Assumptions:
- A table named CUSTOMER already exists.
- You intend to remove one or more rows based on a condition.
- You want transactional, logged deletion that can be rolled back if needed.
Concept / Approach:
Use DELETE to remove rows. Pair it with an appropriate WHERE clause to target only the intended subset. Without a WHERE clause, all rows are removed. DROP is for removing entire objects like tables or views; UPDATE modifies existing values; TRUNCATE removes all rows but does not accept a WHERE clause and has different logging/locking behavior depending on the DBMS.
Step-by-Step Solution:
Choose the DML verb: DELETE.Specify the table: DELETE FROM CUSTOMER.Add a filter: WHERE city = 'Chennai' (example).Wrap the statement in a transaction if required and test with SELECT before committing.Verification / Alternative check:
DBMS documentation shows DELETE as the canonical row-removal command with optional WHERE; DROP removes the table itself; TRUNCATE is a fast, all-rows operation without WHERE.
Why Other Options Are Wrong:
- REMOVE FROM: not valid SQL.
- DROP FROM: drops objects, not rows.
- UPDATE FROM: changes values, does not delete.
- TRUNCATE ... WHERE: TRUNCATE has no WHERE and removes all rows.
Common Pitfalls:
- Forgetting the WHERE clause and deleting all rows unintentionally.
- Violating foreign key constraints; use ON DELETE rules or delete in the correct order.
Final Answer:
DELETE FROM CUSTOMER WHERE ...