H2 Database - Drop

DROP is a command taken from the general grammar of SQL. This command is used to remove a database component and its structure from memory. There are various scenarios with the Drop command which we will discuss in this chapter.
Drop Table
Drop Table is a command that drops the corresponding table and its structure.
Syntax
The following is the general syntax for the drop table command.
DROP TABLE [ IF EXISTS ] tableName [,...] [ RESTRICT | CASCADE]
The command will fail if we use RESTRICT and there is a table with dependent views. All dependent views are removed when we use the CASCADE keyword.
example
In this example, we will drop the table named test using the following query.
DROP TABLE test;
The above query results in the following output.
(6) row(s) effected
Removal scheme
Delete schema is a command that removes the corresponding schema from the database server. This will not work from the current schema.
Syntax
DROP SCHEMA [ IF EXISTS ] schemaName
example
In this example, we will remove the schema named test_schema using the following query.
DROP SCHEMA TEST_SCHEMA;
The above query results in the following output.
(0) row(s) effected
Fall sequence
Drop Sequence is a command used to remove a sequence from a table structure.
Syntax
The following is the general syntax for the delete sequence command.
DROP SEQUENCE [ IF EXISTS ] sequenceName
This command commits an open transaction on this connection.
example
In this example, we will remove the sequence named sequence_id . Below is the command.
DROP SEQUENCE sequence_id;
The above command produces the following output.
(0) row(s) effected
drop view
Drop View is a command used to drop an existing view. All dependent views are also removed if the CASCADE clause is used.
Syntax
Following is the general syntax of the Drop View command.
DROP VIEW [ IF EXISTS ] viewName [ RESTRICT | CASCADE]
example
In this example, we will drop the view named sample_view using the following query.
DROP VIEW sample_view;
The above query results in the following output.