Database Queries - CREATE, DROP, USE-tutorial
Now that you know what databases are and how they are structured,
it is time to start writing real SQL commands to create, remove, and switch between databases.
Think of this as learning the basic commands to manage your workspace in MySQL.
Example
This command creates a new database named SchoolDB.
You can check if It is created successfully by using
Output
2. DROP DATABASE
Syntax
Example
Syntax
Example
This tells MySQL
All your upcoming commands (like CREATE TABLE, INSERT, etc) will apply to this selected database.
Example: Let us see it all together
1. CREATE DATABASE
The CREATE DATABASE command is used to create a new database in MySQL.
Syntax
Syntax
CREATE DATABASE database_name;Example
CREATE DATABASE SchoolDB;This command creates a new database named SchoolDB.
You can check if It is created successfully by using
SHOW DATABASES;Output
information_schemamysqlperformance_schemaSchoolDBTip: Database name are usually written in lowercase or CamelCase (e.g., school_db, SchoolDB).
2. DROP DATABASE
The DROP DATABASE command is used to delete an existing database permanently.
Syntax
DROP DATABASE database_name;Example
DROP DATABASE SchoolDB;Warning: Once you drop a databse, all tables and data inside it are gone forever
So always double check before using this command.
3. USE DATABASE
After creating a database, you need to select it before creating tables or inserting data.
That is done using the USE command.
Syntax
USE database_name;Example
USE SchoolDB;This tells MySQL
Hey, I am working inside the SchoolDB database now.
All your upcoming commands (like CREATE TABLE, INSERT, etc) will apply to this selected database.
Example: Let us see it all together
-- Step 1: Create a databaseCREATE DATABASE SchoolDB;
-- Step 2: View all databasesSHOW DATABASES;
-- Step 3: Use the created databaseUSE SchoolDB;
-- Step 4: Delete a database (optional)DROP DATABASE SchoolDB;Two Minute Drill
- A database is like a container where all your tables and data live.
- Use CREATE DATABASE to make one.
- Use USE to select which one you are working on.
- Use DROP DATABASE carefully it deletes everything inside
- Always verfiy with SHOW DATABASES; to confirm actions.