0
0
MySQLquery~20 mins

Database creation and selection in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Database Creation and Selection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this query?
Given the following SQL commands:

CREATE DATABASE IF NOT EXISTS shop;
USE shop;
SHOW DATABASES LIKE 'shop';

What will be the output of the last command?
MySQL
CREATE DATABASE IF NOT EXISTS shop;
USE shop;
SHOW DATABASES LIKE 'shop';
AAn empty result set
BA single row with the database name 'shop'
CA syntax error due to missing semicolon
DAll databases including 'shop' and others
Attempts:
2 left
💡 Hint
SHOW DATABASES LIKE 'pattern' returns databases matching the pattern.
📝 Syntax
intermediate
1:30remaining
Which option correctly creates a database named 'library'?
Choose the correct SQL statement to create a database named 'library' only if it does not already exist.
ACREATE DATABASE IF NOT EXISTS library;
BCREATE DB IF NOT EXISTS library;
CCREATE DATABASE IF EXIST library;
DCREATE DATABASE library;
Attempts:
2 left
💡 Hint
The correct syntax uses IF NOT EXISTS to avoid errors if the database exists.
query_result
advanced
2:00remaining
What is the result of this sequence of commands?
Consider these commands:

CREATE DATABASE testdb;
USE testdb;
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50));
SHOW TABLES;

What will SHOW TABLES return?
MySQL
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50));
SHOW TABLES;
AA syntax error due to missing semicolon
BAn empty list because no tables exist
CA list containing one table named 'users'
DA list of all tables in all databases
Attempts:
2 left
💡 Hint
SHOW TABLES shows tables in the current database.
🔧 Debug
advanced
1:30remaining
Why does this command fail?
Given the command:

USE shop_db;

It produces an error. What is the most likely cause?
MySQL
USE shop_db;
AIncorrect database name syntax
BMissing semicolon at the end of the statement
CUSE command is not supported in MySQL
DDatabase 'shop_db' does not exist
Attempts:
2 left
💡 Hint
SQL statements must end with a semicolon.
🧠 Conceptual
expert
1:30remaining
Which statement about database selection is true?
Select the correct statement about the USE command in MySQL.
AUSE changes the current database for the session until changed again
BUSE creates a new database if it does not exist
CUSE lists all available databases
DUSE deletes the current database
Attempts:
2 left
💡 Hint
Think about what USE does to your working environment.