Recall & Review
beginner
What is the SQL command to create a new database named 'library'?
The command is
CREATE DATABASE library;. This creates a new empty database called 'library'.Click to reveal answer
beginner
How do you select a database named 'library' to use it for your queries?
Use the command
USE library;. This tells the system to work with the 'library' database for following commands.Click to reveal answer
intermediate
What happens if you try to create a database that already exists without using any extra options?
You will get an error saying the database already exists. To avoid this, use
CREATE DATABASE IF NOT EXISTS database_name;.Click to reveal answer
beginner
Why is it important to select a database before running queries?
Selecting a database tells the system where to look for tables and data. Without selecting, queries may fail or run on the wrong database.
Click to reveal answer
beginner
Write the SQL commands to create a database named 'school' and then select it for use.
First, create the database:
CREATE DATABASE school;<br>Then select it: USE school;Click to reveal answer
Which SQL command creates a new database?
✗ Incorrect
The
CREATE DATABASE command is used to create a new database.How do you tell MySQL to use a specific database for your queries?
✗ Incorrect
The
USE command selects the database for your session.What will happen if you run
CREATE DATABASE test; when 'test' already exists?✗ Incorrect
Trying to create a database that exists causes an error unless you use IF NOT EXISTS.
Which command prevents an error if the database already exists when creating it?
✗ Incorrect
Adding
IF NOT EXISTS avoids errors if the database exists.Why do you need to select a database before running queries?
✗ Incorrect
Selecting a database tells MySQL where to find tables and data for your queries.
Explain how to create a new database and select it for use in MySQL.
Think about the two steps: making the database and then telling MySQL to use it.
You got /3 concepts.
What is the purpose of the 'IF NOT EXISTS' clause in database creation?
It helps avoid errors when the database is already there.
You got /3 concepts.