Use the DBxEnableTable API (where x is a for audio, i for image, or v for video) or the ENABLE TABLE command to enable a table for a DB2 extender.
When enabling a user table, you must also specify table spaces to hold the administrative support tables (and their indexes) that go with it. One or more of the table spaces that are specified can be a null value, in which case a default table space is used.
EEE Only: When enabling a table for an extender in a partitioned environment, the table space that you specify should be defined in a nodegroup that includes all the nodes in the partitioned database system. Also, the table space specified must be located in the same nodegroup as the user table.
EEE Only: You cannot use a DB2 extender column as a partitioning key column in a partitioned database environment.
You need Control or Alter authority for the user table. The database must be enabled before you enable a table in it.
In the following examples, a table is enabled to hold image data using the default table space. The database is already enabled.
Using the API: In the following example, before enabling the table, the code creates the table and commits changes. The example includes some error-checking code. The complete sample program is in the ENABLE.C file in the SAMPLES subdirectory.
Figure 11. Sample code that enables a table
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 --------------------------------------------*/ |
Using the db2ext command line: In this example, the table already exists, and the database is enabled.
enable table employee for db2image