The DropTable class of the SQL Statement Builder provides an entry point to defining a DROP TABLE SQL statement.
-
Create an instance of the
DropTableclass through theStatementFactoryDropTable dropTable = StatementFactory.getInstance().dropTable("tableName");
-
Add available options if necessary.
The following options are currently supported:
IF EXISTSCASCADE CONSTRAINTS
Example:
dropTable.ifExists().cascadeConstraints();
-
Render the instance of
DropTableclass. Click here for more information on Rendering SQL Statement.The complete example code:
DropTable dropTable = StatementFactory.getInstance().dropTable("tableName"); // optional step: add additional clauses dropTable.ifExists().cascadeConstraints(); // Rendering // optional step: add configuration StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); DropTableRenderer renderer = DropTableRenderer.create(config); dropTable.accept(renderer); String renderedString = renderer.render();