Challenge - 5 Problems
Database Creation and Selection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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?
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';
Attempts:
2 left
💡 Hint
SHOW DATABASES LIKE 'pattern' returns databases matching the pattern.
✗ Incorrect
The command SHOW DATABASES LIKE 'shop' returns only databases named exactly 'shop'. Since it was created, it appears as one row.
📝 Syntax
intermediate1: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.
Attempts:
2 left
💡 Hint
The correct syntax uses IF NOT EXISTS to avoid errors if the database exists.
✗ Incorrect
Option A uses the correct syntax to create the database only if it does not exist. Options B and C are invalid syntax, and A will error if the database exists.
❓ query_result
advanced2: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?
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;
Attempts:
2 left
💡 Hint
SHOW TABLES shows tables in the current database.
✗ Incorrect
After creating the 'users' table in 'testdb' and selecting it with USE, SHOW TABLES returns the list of tables in 'testdb', which includes 'users'.
🔧 Debug
advanced1:30remaining
Why does this command fail?
Given the command:
USE shop_db;
It produces an error. What is the most likely cause?
USE shop_db;
It produces an error. What is the most likely cause?
MySQL
USE shop_db;
Attempts:
2 left
💡 Hint
SQL statements must end with a semicolon.
✗ Incorrect
If the command includes a semicolon, the most likely cause of error is that the database 'shop_db' does not exist. USE is valid and database names can have underscores.
🧠 Conceptual
expert1:30remaining
Which statement about database selection is true?
Select the correct statement about the USE command in MySQL.
Attempts:
2 left
💡 Hint
Think about what USE does to your working environment.
✗ Incorrect
The USE command sets the current database for the session. It does not create, list, or delete databases.