Vidyalelo
MySQL · Q254

MySQL

Programming · MySQL · question 254

Q254

Find out the logical error in the following MySQL code snippet? CREATE TABLE person ( person_id VARCHAR(20), Name VARCHAR (20), Address VARCHAR (20), Mobile_no SMALLINT );

A.
Lesser number of columns
B.
Incorrect definition
C.
Primary key is missing
Answer
D.
None of the mentioned

Answer: Option C

Solution

Answer: Option C
Solution:
This code snippet is trying to create a table named "person" with four columns:

* person_id (a text field of length 20 characters)
* Name (a text field of length 20 characters)
* Address (a text field of length 20 characters)
* Mobile_no (a small integer)

The problem is with the Mobile_no column. Mobile phone numbers are typically too long for a SMALLINT data type.

A SMALLINT can hold a maximum value of 32,767. This is not enough to store a typical mobile number.

The correct way to define this column would be using VARCHAR for the mobile number, as it is a text field.

Therefore, the logical error in the code snippet is "Incorrect definition" (Option B).