Creation of tables with XML columns

To create tables with XML columns, you specify columns with the XML data type in the CREATE TABLE statement. A table can have one or more XML columns.

You do not specify a length when you define an XML column. There is no architectural limit on the size of an XML value in a database. However, textual XML data that is exchanged with a DB2® database is limited to 2 GB-1, so the effective limit of an XML column is 2 GB-1.

Like a LOB column, an XML column holds only a descriptor of the column. The data is stored separately.

Start of changeWhen you define an XML column, you can add an XML type modifier. An XML type modifier associates a set of one or more XML schemas with the XML data type. You can use an XML type modifier to cause all XML documents that are stored in an XML column to be validated according to one of the XML schemas that is specified in the type modifier.End of change

Start of changeWhen you create a table with an XML column in a universal table space, DB2 maintains multiple versions of XML documents during update operations, to enhance concurrency and memory usage.End of change

Example: A table for customer data contains two XML columns. The definition looks like this:
CREATE TABLE CUSTOMER (CID BIGINT NOT NULL PRIMARY KEY,
                       INFO XML,
                       HISTORY XML)
Start of changeExample: A table for customer data contains an XML column named CONTENT. The documents in the XML column need to be validated according to XML schema SYSXSR.PO1, which has already been registered. The definition looks like this: Start of change
CREATE TABLE PURCHASEORDERS(
  ID INT NOT NULL,
  CONTENT XML(XMLSCHEMA ID SYSXSR.PO1))
End of change End of change