Dropping Tables and Indexes

Learn to drop Oracle NoSQL Database tables and indexes using Oracle NoSQL Database SDK for Spring Data.

To drop the tables and indexes on the fields in tables, you use NosqlTemplate.runTableRequest() or NosqlTemplate.dropTableIfExists() methods.

Create the AppConfig class that extends AbstractNosqlConfiguration class to provide the connection details of the database. For details, see Accessing Oracle NoSQL Database Using Spring Data Framework.

In the application, you instantiate the NosqlTemplate class by providing the NosqlTemplate.create(NosqlDbConfig nosqlDBConfig) method with the instance of the AppConfig class. You then drop the table using the NosqlTemplate.dropTableIfExists() method. The NosqlTemplate.dropTableIfExists() method drops the table and returns true if the result indicates a change of the table's state to DROPPED or DROPPING.

Example 2-7 Dropping Tables and Indexes using Spring Data Framework

The following code sample shows how to drop the Student table.
 
try {
    AppConfig config = new AppConfig();
    NosqlTemplate tabledrop = NosqlTemplate.create(config.nosqlDbConfig());
    Boolean result = tabledrop.dropTableIfExists("Student");
    if (result == true) {
        System.out.println("Table dropped successfully");
    } else {
        System.out.println("Failed to drop table");
    }
} catch (Exception e) {
    System.out.println("Exception creating index" + e);
}