Examveda

Find the error in the following SQL statement?
CREATE TABLE person
( person_id SMALLINT, name VARCHAR, LAST VARCHAR, Bith_date DATE
CONSTRAINTS pk_person PRIMARY KEY (person_id));
INSERT INTO person
VALUES( person_id, name, LAST, Birth_date)
(1,’s’,’p’, 24-1991-01);

A. In correct data value

B. No error

C. Any other error

D. None of the mentioned

Answer: Option A

Solution (By Examveda Team)

This SQL code has a few errors. Let's break them down:
Error 1: Incorrect Column Names
* In the `CREATE TABLE` statement, you have a column named `LAST`. It should be `Last_name` to follow best practices and avoid confusion. * The column `Bith_date` is misspelled and should be `Birth_date`.
Error 2: Incorrect Syntax for `INSERT INTO`
* The `INSERT INTO` statement has incorrect syntax. You should list the column names and their values directly in the query: `INSERT INTO person (person_id, name, Last_name, Birth_date) VALUES (1, 's', 'p', '1991-01-24');`
Error 3: Incorrect Date Format
* The date format `24-1991-01` is incorrect. MySQL expects the standard format `YYYY-MM-DD`, so it should be `1991-01-24`.
The Correct Statement
```sql CREATE TABLE person ( person_id SMALLINT, name VARCHAR(255), Last_name VARCHAR(255), Birth_date DATE, CONSTRAINT pk_person PRIMARY KEY (person_id) ); INSERT INTO person (person_id, name, Last_name, Birth_date) VALUES (1, 's', 'p', '1991-01-24'); ```
Therefore, the answer is Option A: Incorrect Data Value . The data value for `Birth_date` is in the wrong format.

This Question Belongs to MySQL >> MySQL Miscellaneous

Join The Discussion

Related Questions on MySQL Miscellaneous