Bird
Raised Fist0
MySQLquery~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the CREATE DATABASE command do in MySQL?
easy
A. It selects a database to use.
B. It deletes an existing database.
C. It creates a new database to store data.
D. It shows all databases available.

Solution

  1. Step 1: Understand the purpose of CREATE DATABASE

    This command is used to make a new database where you can store tables and data.
  2. Step 2: Differentiate from other commands

    Deleting databases uses DROP DATABASE, selecting uses USE, and showing uses SHOW DATABASES.
  3. Final Answer:

    It creates a new database to store data. -> Option C
  4. Quick Check:

    CREATE DATABASE = create new database [OK]
Hint: Remember: CREATE makes new, USE picks existing [OK]
Common Mistakes:
  • Confusing CREATE with USE command
  • Thinking CREATE deletes databases
  • Mixing CREATE with SHOW DATABASES
2. Which of the following is the correct syntax to select a database named shop in MySQL?
easy
A. SELECT DATABASE shop;
B. CHOOSE DATABASE shop;
C. OPEN DATABASE shop;
D. USE shop;

Solution

  1. Step 1: Recall the command to select a database

    In MySQL, the command to start using a database is USE database_name;.
  2. Step 2: Check each option's syntax

    Only USE shop; is valid syntax. Others are incorrect commands.
  3. Final Answer:

    USE shop; -> Option D
  4. Quick Check:

    USE selects database [OK]
Hint: Use USE to pick your database [OK]
Common Mistakes:
  • Using SELECT instead of USE
  • Trying OPEN or CHOOSE commands (not valid)
  • Missing semicolon at end
3. What will be the result of the following commands?
CREATE DATABASE testdb;
USE testdb;
SHOW TABLES;
medium
A. Lists all tables in the database 'testdb'.
B. Shows an error because 'testdb' does not exist.
C. Creates a table named 'testdb'.
D. Shows all databases available.

Solution

  1. Step 1: Create and select the database

    The command CREATE DATABASE testdb; makes a new database named 'testdb'. Then USE testdb; selects it for use.
  2. Step 2: Show tables in the selected database

    SHOW TABLES; lists all tables in the current database. Since 'testdb' is empty, it will show an empty list but no error.
  3. Final Answer:

    Lists all tables in the database 'testdb'. -> Option A
  4. Quick Check:

    SHOW TABLES lists tables in current DB [OK]
Hint: SHOW TABLES lists tables in current database [OK]
Common Mistakes:
  • Thinking SHOW TABLES shows databases
  • Assuming error because database is new
  • Confusing CREATE DATABASE with CREATE TABLE
4. Identify the error in the following MySQL commands:
CREATE DATABASE mydb
USE mydb;
medium
A. Database name 'mydb' is invalid.
B. Missing semicolon after CREATE DATABASE statement.
C. USE command cannot follow CREATE DATABASE.
D. CREATE DATABASE should be lowercase.

Solution

  1. Step 1: Check syntax of each command

    MySQL commands must end with a semicolon. The first line misses a semicolon after CREATE DATABASE mydb.
  2. Step 2: Verify other parts

    The database name 'mydb' is valid, USE can follow CREATE DATABASE, and case does not matter for commands.
  3. Final Answer:

    Missing semicolon after CREATE DATABASE statement. -> Option B
  4. Quick Check:

    Semicolon ends commands [OK]
Hint: Always end SQL commands with semicolon [OK]
Common Mistakes:
  • Forgetting semicolon at end of statements
  • Thinking database names must be uppercase
  • Believing USE cannot follow CREATE DATABASE
5. You want to create two databases named sales and inventory, then select sales to work with. Which sequence of commands is correct?
hard
A. CREATE DATABASE sales; CREATE DATABASE inventory; USE sales;
B. USE sales; CREATE DATABASE sales; CREATE DATABASE inventory;
C. CREATE DATABASE sales, inventory; USE sales;
D. CREATE DATABASE sales; USE inventory; CREATE DATABASE inventory;

Solution

  1. Step 1: Create both databases separately

    Each database must be created with its own CREATE DATABASE command ending with a semicolon.
  2. Step 2: Select the 'sales' database to use

    After creating, use USE sales; to select the 'sales' database for work.
  3. Final Answer:

    CREATE DATABASE sales; CREATE DATABASE inventory; USE sales; -> Option A
  4. Quick Check:

    Create each DB then USE the one you want [OK]
Hint: Create each DB separately, then USE the desired one [OK]
Common Mistakes:
  • Trying to create multiple databases in one command
  • Using USE before creating the database
  • Selecting wrong database after creation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard