IBM Books

XML Extender Administration and Programming

Creating or altering an XML table

To store intact XML documents in a table, you must create or alter a table so that it contains a column with an XML user-defined type (UDT). The table is known as an XML table, a table that contains XML documents. The table can be an altered table or a new table. When a table contains a column of XML type, you can enable the column for XML.

You can alter an existing table with a column of XML type using the administration wizard, or using the DB2 command shell.

Using the adminstration wizard

  1. Set up and start the administration wizard. See Starting the administration wizard for details.
  2. Click Work with XML columns from the LaunchPad window. The Select a task window opens.
  3. Click Add an XML Column. The Add an XML column window opens.
  4. Select the name of the table from the Table name pull-down menu, or type the name of the table you want to alter. For example:
    SALES_DB
    
  5. Type the name of the column to be added to the table in the Column name field. For example:
    ORDER
    
  6. Select the UDT for the column from the Column type pull-down menu. For example:
    XMLVARCHAR
    
  7. Click Finish to add the column of XML type.

From the DB2 command shell

Create or alter a table with a column of an XML type in the column clause of the CREATE TABLE or ALTER TABLE statement.

Example: In the sales application, you might want to store an XML-formatted line item order in a column called ORDER of an application table called SALES_TAB. This table also has the columns INVOICE_NUM and SALES_PERSON. Because it is a small order, you store it using the XMLVARCHAR type. The primary key is INVOICE_NUM. The following CREATE TABLE statement creates the table with a column of XML type:

CREATE TABLE sales_tab( 
              invoice_num  char(6) NOT NULL PRIMARY KEY,
              sales_person     varchar(20),
              order            XMLVarchar);               


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]