Let us try to delete a database that doesn't exist in the database system using the following query statement − If you try to drop the database that doesn't exist Example Let us verify whether the database is deleted or not using the following query − On executing the given program, the output is displayed as follows − Let us try to delete an existing database in the database system using the following query statement − Here, the “DatabaseName” is the name of the database that we want to delete. Syntaxįollowing is the syntax of the DROP DATABASE IF EXISTS statement in SQL − If the database does not exist in the database system, the "DROP DATABASE IF EXISTS" statement does not raise an error, but it simply terminates without taking any action. The DROP DATABASE IF EXISTS statement in SQL includes a condition to check whether the database exists before trying to delete it. The above query returns an error statement because the database we are trying to delete doesn't exist in the database system −Ĭannot drop the database 'testDB1', because it does not exist or you do not have permission. Now, let us try to delete a database that doesn't exist in the database system − That's it! we have successfully deleted a database in SQL. Once we have deleted the database, we can verify whether it is deleted or not using the following query − Now, let us try to delete a single existing database using the DROP DATABASE statement − Let us verify whether the databases are created or not using the following query − Exampleįirst of all, let us create multiple databases into database system using the following query − Here, the “DatabaseName” is the name of the database that we want to delete.Īlways the database name should be unique within the RDBMS. Syntaxįollowing is the syntax to delete a database in SQL − Note − Make sure you have the necessary privilege before deleting any database using the DROP DATABASE statement. If we try to delete the database while others users are connected to it, then it can cause data corruption or other issues. It is also important to ensure that no other user or application is currently connected to the database that we want to delete.It is important to make sure that we have to perform the backup of the database that we are going to delete because once the “DROP DATABASE” statement is executed, all the data and database objects in the database will be permanently deleted and cannot be recovered.The Following are the most important points to remember before we are trying to delete the database − The DROP DATABASE statement in SQL is used to delete a database along with all the data such as tables, views, indexes, stored procedures, and constraints.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |