Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Once databases are created, you must know how to switch your session's working context using the USE statement, verify your active database context, and safely remove unneeded schemas using DROP DATABASE.
USE)In SQL, queries need to know which database your tables belong to. The USE statement sets the current default database for the active client connection session:
Once selected, any query you execute without a schema prefix automatically targets that database:
Even if your active session is set to ecommerce_platform, you can still query tables in another database without switching by using dot notation (database_name.table_name):
To verify which database is currently selected in your session, call the built-in function DATABASE():
If no database has been selected yet (e.g., right after logging into the CLI), SELECT DATABASE(); returns NULL.
DROP DATABASE)When a project is decommissioned or test data needs cleanup, you remove the database using DROP DATABASE:
DROP DATABASE is immediate, permanent, and irrevocable! It physically deletes the database directory on disk, destroying all tables, indexes, data rows, views, and stored routines. It cannot be undone by a ROLLBACK statement!DROP DATABASE vs DROP SCHEMAIn MySQL, the keywords DATABASE and SCHEMA are completely interchangeable synonyms:
SELECT DATABASE(); or verify your active connection host before issuing DROP DATABASE to ensure you are not accidentally connected to production!DROP privilege from normal development users. Only Senior DBAs should possess the permission to drop databases.mysqldump backup exists.DROP DATABASE is executed?DROP DATABASE operation be undone using a standard SQL ROLLBACK command?DROP DATABASE db_name; and DROP SCHEMA db_name; compare?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Creating & Listing Databases | Character Sets & Collations (utf8mb4) |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.