刪除表格與索引

您可以使用 TableRequest API 刪除 NoSQL 表格。

TableRequest 指定的作業執行為非同步。這些作業可能會長時間執行。TableResult 會從 TableRequest 作業傳回,且會封裝表格的狀態。請參閱 Oracle NoSQL Java SDK API Reference ,瞭解 TableRequest 類別及其方法的詳細資訊。

Download the full code AlterTable.java from the examples here.

/*Drop the table*/
private static void dropTab(NoSQLHandle handle) throws Exception {
   String dropTableDDL = "DROP TABLE " + tableName;
   TableRequest treq = new TableRequest().setStatement(dropTableDDL);
   TableResult tres = handle.tableRequest(treq);
   tres.waitForCompletion(handle, 60000, /* wait 60 sec */
       1000); /* delay ms for poll */
   System.out.println("Table " + tableName + " is dropped");
}

您可以使用 borneo.TableRequest 類別來刪除表格。所有對 borneo.NoSQLHandle.table_request() 的呼叫都是非同步的,因此必須檢查結果並呼叫 borneo.TableResult.wait_for_completion(),以等待作業完成。請參閱 Oracle NoSQL Python SDK API Reference ,瞭解 table_request 及其方法的詳細資訊。

此處的範例下載完整程式碼 AlterTable.py

def drop_table(handle):
   statement = '''DROP TABLE stream_acct'''
   request = TableRequest().set_statement(statement)
   table_result = handle.do_table_request(request, 40000, 3000)
   table_result.wait_for_completion(handle, 40000, 3000)
   print('Dropped table: stream_acct')

您可以使用 TableRequest 類別來刪除表格。TableRequest 指定的作業執行為非同步。這些作業可能會長時間執行。此要求是用來作為 Client.DoTableRequest() 作業的輸入,它會傳回可用來輪詢的 TableResult,直到表格達到所需的狀態為止。請參閱 Oracle NoSQL Go SDK API Reference ,瞭解 TableRequest 類別各種方法的詳細資訊。

此處的範例下載完整程式碼 AlterTable.go

//drop an existing table
func dropTable(client *nosqldb.Client, err error, tableName string)(){
   stmt := fmt.Sprintf("DROP TABLE %s",tableName)
   tableReq := &nosqldb.TableRequest{
		Statement: stmt,
   }
   tableRes, err := client.DoTableRequest(tableReq)
   return
}

您可以使用 tableDDL 方法來刪除表格。此方法為非同步,且會傳回 Promise TableResultTableResult 是純 JavaScript 物件,可封裝 DDL 作業之後的表格狀態。如需方法詳細資訊,請參閱 NoSQLClient 類別。

Download the full JavaScript code AlterTable.js from the examples here and the full TypeScript code AlterTable.ts from the examples here.

//drop a table
async function dropTable(handle) {
   const dropDDL = `DROP TABLE ${TABLE_NAME}`;
   let res =  await handle.tableDDL(dropDDL);
   console.log('Table dropped: ' + TABLE_NAME);
}

您可以使用 ExecuteTableDDLAsyncExecuteTableDDLWithCompletionAsync 其中一個方法來刪除表格。這兩種方法都會傳回 Task<TableResult>TableResult 執行處理會封裝 DDL 作業之後的表格狀態。如需這些方法的詳細資訊,請參閱 Oracle NoSQL Dotnet SDK API Reference

Download the full code AlterTable.cs from the examples here.

private static async Task dropTable(NoSQLClient client){
   var sql = $@"DROP TABLE {TableName}";
   var tableResult = await client.ExecuteTableDDLAsync(sql);
   // Wait for the operation completion
   await tableResult.WaitForCompletionAsync();
   Console.WriteLine("  Table {0} is dropped", tableResult.TableName);
}

您可以使用 TableRequest API 刪除 NoSQL 表格的索引。

TableRequest 類別所指定的作業執行為非同步。這些作業可能會長時間執行。TableResult 會從 TableRequest 作業傳回,且會封裝表格的狀態。請參閱 Oracle NoSQL Java SDK API Reference ,瞭解 TableRequest 類別及其方法的詳細資訊。

Download the full code Indexes.java from the examples here.

/* Drop the index acct_episodes*/
private static void dropIndex(NoSQLHandle handle) throws Exception {
   String dropIndexDDL = "DROP INDEX acct_episodes ON " + tableName;
   TableRequest treq = new TableRequest().setStatement(dropIndexDDL);
   TableResult tres = handle.tableRequest(treq);
   tres.waitForCompletion(handle, 60000, /* wait 60 sec */
            1000); /* delay ms for poll */
   System.out.println("Index acct_episodes on " + tableName + " is dropped");
}

您可以使用 borneo.TableRequest 類別來刪除表格索引。所有對 borneo.NoSQLHandle.table_request() 的呼叫都是非同步的,因此必須檢查結果並呼叫 borneo.TableResult.wait_for_completion(),以等待作業完成。請參閱 Oracle NoSQL Python SDK API Reference ,瞭解 table_request 及其方法的詳細資訊。

Download the full code Indexes.py from the examples here.

#drop the index
def drop_index(handle):
   statement = '''DROP INDEX acct_episodes ON stream_acct'''
   request = TableRequest().set_statement(statement)
   table_result = handle.do_table_request(request, 40000, 3000)
   table_result.wait_for_completion(handle, 40000, 3000)
   print('Index acct_episodes on the table stream_acct is dropped')

您可以使用 TableRequest 類別來刪除表格索引。TableRequest 指定的作業執行為非同步。這些作業可能會長時間執行。此要求是用來作為 Client.DoTableRequest() 作業的輸入,它會傳回可用來輪詢的 TableResult,直到表格達到所需的狀態為止。請參閱 Oracle NoSQL Go SDK API Reference ,瞭解 TableRequest 類別各種方法的詳細資訊。

此處的範例下載完整程式碼 Indexes.go

//drops an index from a table
func dropIndex(client *nosqldb.Client, err error, tableName string)(){
   stmt := fmt.Sprintf("DROP INDEX acct_episodes ON %s",tableName)
   tableReq := &nosqldb.TableRequest{
		Statement: stmt,
   }
   tableRes, err := client.DoTableRequest(tableReq)
   if err != nil {
      fmt.Printf("cannot initiate DROP INDEX request: %v\n", err)
      return
   }
   // The drop index request is asynchronous, wait for drop index to complete.
   _, err = tableRes.WaitForCompletion(client, 60*time.Second, time.Second)
   if err != nil {
      fmt.Printf("Error finishing DROP INDEX request: %v\n", err)
      return
   }
   fmt.Println("Dropped index acct_episodes on table ", tableName)
   return
}

您可以使用 tableDDL 方法來刪除表格索引。此方法為非同步,且會傳回 Promise TableResultTableResult 是包含 DDL 作業狀態 (例如其 TableState、名稱、綱要及其 TableLimits) 的純 JavaScript 物件。如需方法詳細資訊,請參閱 NoSQLClient 類別。

Download the full JavaScript code Indexes.js from the examples here and the full TypeScript code Indexes.ts from the examples here.

//drops an index
async function dropIndex(handle) {
   const dropindDDL = `DROP INDEX acct_episodes ON ${TABLE_NAME}`;
   let res =  await handle.tableDDL(dropindDDL);
   console.log('Index acct_episodes is dropped from table: ' + TABLE_NAME);
}

您可以使用 ExecuteTableDDLAsyncExecuteTableDDLWithCompletionAsync 其中一個方法來刪除表格索引。這兩種方法都會傳回 Task<TableResult>TableResult 執行處理包含 DDL 作業的狀態,例如 TableState 和表格綱要。如需這些方法的詳細資訊,請參閱 Oracle NoSQL Dotnet SDK API Reference

Download the full code Indexes.cs from the examples here.

private static async Task dropIndex(NoSQLClient client){
   var sql = $@"DROP INDEX acct_episodes on {TableName}";
   var tableResult = await client.ExecuteTableDDLAsync(sql);
   // Wait for the operation completion
   await tableResult.WaitForCompletionAsync();
   Console.WriteLine(" Index acct_episodes is dropped from table Table {0}",
                tableResult.TableName);
}

相關主題