使用 DBxEnableTable API (其中 x 若是 a 代表音效,i 代表 影像,或 v 代表視訊) 或 ENABLE TABLE 指令,以啟用 DB2 Extender 的表格。
啟用使用者表格時,您也必須指定表格空間來保留隨附的管理支援表格 (及其索引)。 指定的一或多個表格空間可以是 NULL 值,而在該情況中會使用預設表格空間。
僅適用於 EEE:在已分割環境中啟用 Extender 的表格時,您指定的表格空間應 定義於一個節點群組,而該節點群組包含已分割資料庫系統中的所有節點。 而且,指定的表格空間必須與使用者表格位於相同的節點群組中。
僅適用於 EEE: 在已分割資料庫環境中,DB2 Extender 直欄不能作為分割鍵值直欄使用。
對於使用者表格,您需要「控制」(Control) 或「變更」(Alter) 權限。 在資料庫中啟用表格之前, 必須先啟用資料庫。
下列範例中,會使用預設表格空間,讓表格來保留影像資料。 資料庫已啟用。
使用 API: 在下列範例中,啟用表格之前, 程式碼會建立表格和 COMMIT 變更。 該範例包括一些錯誤檢查碼。 完整範例程式位於 SAMPLES 次目錄中的 ENABLE.C 檔。
SQLCHAR szCreate_DB2UDB[]="CREATE TABLE %s(%s mmdbsys.DB2Image, %s mmdbsys.DB2Video, %s mmdbsys.DB2Audio, artist varchar(25), title varchar(25) stock_no char(11), tw char(10), price char(10))"; SQLRETURN rc = SQL_SUCCESS; SQLINTEGER sqlcode = 0; char errorMsgText[MMDB_ERROR_MSG_TEXT_LEN+1]; char tableName[8+18+1] = "sobay_catalog"; char audioColumn[18+1] = "music"; char imageColumn[18+1] = "covers"; char videoColumn[18+1] = "video"; char *program = "enable"; char *step; /*-----create table --------------------------------------------------*/ printf("%s: Creating table ......\n", program); if (!SERVER_IS_DB2390) sprintf((char*) buffer, (char*) szCreate_DB2UDB, tableName, imageColumn, videoColumn, audioColumn): rc = SQLAllocStmt(hdbc, &hstmt); cliCheckError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT, rc); rc = SQLExecDirect(hstmt, buffer, SQL_NTS); cliCheckError(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt, rc); /*---- enable table for image extender ---------------------------------*/ printf("%s: Enabling table......\n", program); step="DBiEnableTable"; if (!SERVER_IS_DB2390) rc = DBiEnableTable(NULL,tableName); } if (rc < 0) { printf("%s: %s failed!\n", program, step); printMsg(rc); DBiGetError(&sqlcode, errorMsgText); if (sqlcode) printf("sqlcode=%i, "sqlcode"); printf("errorMsgText=%s\n", errorMsgText); } else if (rc > 0) { printf("%s: %s, warning detected.\n", program, step); printMsg(rc); DBiGetError(&sqlcode, errorMsgText); printf("warningMsgText=%s\n", errorMsgText); } else printf("%s: %s OK\n", program, step) /*---- end of enable table --------------------------------------------*/ |
使用 db2ext 指令行:在本範例中,表格已存在,而且已啟用資料庫。
enable table employee for db2image