Answer: Deleting a Database
Find a detailed explanation of deleting a database.
Solution
The solution is given below:
-- The query to delete a databaseDROP DATABASE IF EXISTS PastInnovations;-- Retrieve the list of databasesSHOW DATABASES;
Code explanation
The explanation of the solution code is given below:
Line 2: The
DROP DATABASE
statement deletes the database namedPastInnovations
along with all its tables and data.Line 4: The
SHOW DATABASES
command displays a list of all databases to confirm which databases are still available.
Recalling relevant concepts
We have covered the following concepts in this question:
The
DROP DATABASE
statementChecking for available databases
Let’s discuss the concepts used in the solution:
We use the
DROP DATABASE
command followed by the desired database name to delete a database.
DROP DATABASE DatabaseName;
We use the
SHOW DATABASES
command to list the names of all the available databases.
SHOW DATABASES;
Alternate solutions
Let’s discuss the alternate solutions for the same problem in this section:
Dynamic SQL
A database can be deleted using the dynamic SQL. While using dynamic SQL ...