Sql Database | Drop database statement in sql - sql - sql tutorial - learn sql
- To use DROP DATABASE , you need the DROP privilege on the database.
- DROPSCHEMA is a synonym for DROP DATABASE .
- When a database is dropped, user privileges on the database are not automatically dropped.
- Sometimes we may decide that we need to delete of an entire database in the RDBMS.
- In fact, if we cannot do so, we would be faced with a maintenance nightmare.
- Fortunately, SQL allows us to do it, as we can use the DROP DATABASE command.
Syntax
- So, if we wanted to drop the HOLIDAYS database that we created in the CREATE DATABASE section, we simply type
- Please note that any table that is still in the database will also disappear once the database is dropped.
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialDROP STATEMENT CAUTION:
DROP STATEMENT CAUTION:
- DROP is a powerful statement. A backup of data for a database to be deleted or drop is the best quick cheap recovery solution. So be smart with this statement!
- To use DROP DATABASE, one needs to have the DROP privilege on the database.
Examples
A. Dropping a single database
- The following example removes the Sales database.
B. Dropping multiple databases
- Applies to: SQL Server 2008 through SQL Server 2017.
- The following example removes each of the listed databases.
C. Dropping a database snapshot
- Applies to: SQL Server 2008 through SQL Server 2017.
- The following example removes a database snapshot, named sales_snapshot0600, without affecting the source database.
Example:
- Each database has its own namespace for tables.
- You can reuse the same table names in each database.
- You can either USE a database after creating it,
- or qualify all references to the table name with the name of the database.
- Here, tables T2 and T3 are both created in the TEMP database.
- You cannot drop a database while it is selected by the USE statement.
- ERROR: Analysis Exception: Cannot drop current default database: temp
- The always-available database 'default' is a convenient one to USE
- before dropping a database you created.
- Before dropping a database, first drop all the tables inside it, or in CDH 5.5 and higher use the CASCADE clause.
- The always-available database 'default' is a convenient one to USE
- before dropping a database you created.
- ERROR: Impala Runtime Exception: Error making 'drop Database' RPC to Hive Meta store:
- CAUSED BY: Invalid Operation Exception: Database temp is not empty
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorialOutput
Output
Name |
---|
t3 |