MySQL Questions and Answers – When Good Statements Go Bad

This set of MySQL Multiple Choice Questions & Answers (MCQs) focuses on “When Good Statements Go Bad”

1. Which command is used to remove existing tables or database?
a) DROP TABLE
b) DELETE
c) Either DROP TABLE or DELETE
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

2. Which command is used to display all the existing tables in a database?
a) SHOW TABLES
b) SHOW TABLE
c) SHOW
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

3. Is duplicate entry of primary key is allowed in SQL?
a) Yes
b) No
c) Depends
d) None of the mentioned
View Answer

Answer: b
Explanation: Primary key are used to uniquely define attributed stored in the table.
advertisement
advertisement

4. Is duplicate entry of other attributes are allowed in SQL?
a) Yes
b) No
c) Depends
d) None of the mentioned
View Answer

Answer: a
Explanation: Duplicate values are allowed but not for Primary Key attributes.

5. Which is the correct format to store date in the SQL?
a) DEC-01-1991
b) 01-1991-11
c) 01-DEC-12
d) 1991-11-01
View Answer

Answer: d
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Which of the following are the valid “database datatypes” in Mysql?
a) Numerical
b) Temporal
c) Text
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

7. Find the error in the following SQL statement?

advertisement
CREATE TABLE person
( person_id SMALLINT, name VARCHAR, LAST VARCHAR
  CONSTRAINTS pk_person PRIMARY KEY (person_id));
  INSERT INTO person
  VALUES( person_id, name, LAST)
  (1, ’s’, ’p’);
  INSERT INTO person
  ( person_id, name, LAST)
  VALUES(1,’s’,’p’);

a) No error
b) Error, Duplicate value
c) Any other error
d) None of the mentioned
View Answer

Answer: b
Explanation: Primary can never have same value.
advertisement

8. 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
View Answer

Answer: a
Explanation: Format for DATE datatype is YYYY-MM-DD.

9. Which Key is used to link two tables in Mysql?
a) Primary Key
b) Foreign Key
c) Both Primary and Foreign Key
d) None of the mentioned
View Answer

Answer: b
Explanation: Foreign Key is only the Key which can link two tables.

10. Which line of the following statements will produce error?
a) SELECT * FROM person WHERE person_id=1;
b) SELECT pname FROM person;
c) SELECT pname, lname, person_id FROM person;
d) None of the mentioned
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – MySQL Database.

To practice all areas of MySQL Database, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.