Dynamodb 简明教程
DynamoDB - Delete Table
在本章中,我们将讨论如何删除表格以及删除表格的不同方法。
表删除是一个简单的操作,只需要表名就可以进行。使用 GUI 控制台、Java 或其他任何选项执行此任务。
Delete Table using the GUI Console
通过首先访问控制台执行删除操作:
从导航窗格中选择 Tables ,并从表列表中选择要删除的表,如下图所示。
最后,选择 Delete Table 。选择“删除表”后,会出现一个确认对话框。然后,你的表就被删除了。
Delete Table using Java
使用 delete 方法删除表。下面给出示例以更好地解释该概念。
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Table;
public class ProductsDeleteTable {
public static void main(String[] args) throws Exception {
AmazonDynamoDBClient client = new AmazonDynamoDBClient()
.withEndpoint("http://localhost:8000");
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Products");
try {
System.out.println("Performing table delete, wait...");
table.delete();
table.waitForDelete();
System.out.print("Table successfully deleted.");
} catch (Exception e) {
System.err.println("Cannot perform table delete: ");
System.err.println(e.getMessage());
}
}
}