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
);
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
D. None of the mentioned
Answer: Option C
Solution (By Examveda Team)
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).
Related Questions on MySQL Miscellaneous
How is communication established with MySQL?
A. SQL
B. Network calls
C. A programming language like C++
D. APIs
Which type of database management system is MySQL?
A. Object-oriented
B. Hierarchical
C. Relational
D. Network

Join The Discussion