Examveda

In the following MySQL command how many rows will be deleted?
DELETE person
WHERE person_id<10;
/*person_id is a primary key */

A. 0-9

B. 1-7

C. No row

D. None of the mentioned

Answer: Option A

Solution (By Examveda Team)

This question asks about deleting rows from a table using a DELETE statement in MySQL. Let's break it down:
1. DELETE Statement:
The `DELETE` statement is used to remove rows from a table. It follows the syntax:
`DELETE FROM table_name WHERE condition;`
2. The `WHERE` Clause:
The `WHERE` clause specifies which rows to delete based on a condition. In this case, the condition is `person_id < 10`. This means we're targeting rows where the `person_id` column is less than 10.
3. Primary Key:
The question mentions that `person_id` is a primary key. A primary key in a table ensures that each row has a unique identifier. It cannot have duplicate values.
4. Understanding the Logic:
Since `person_id` is a primary key, it cannot have duplicate values. This means that any value less than 10 in `person_id` will be unique.
5. Answer:
Therefore, the `DELETE` statement will delete all rows where `person_id` is less than 10. The correct answer is Option A: 0-9.
In simpler terms:
The command will remove all the rows with `person_id` from 0 to 9, as it's a primary key and there cannot be duplicates.

This Question Belongs to MySQL >> MySQL Miscellaneous

Join The Discussion

Related Questions on MySQL Miscellaneous