Recall & Review
beginner Click to reveal answer
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'.beginner Click to reveal answer
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.intermediate Click to reveal answer
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;.beginner Click to reveal answer
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.
beginner Click to reveal answer
Write the SQL commands to create a database named 'school' and then select it for use.
First, create the database:
Then select it:
CREATE DATABASE school;Then select it:
USE school;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.
