Lesson 1: Creating a Db2 database and table that can store XML data
This lesson shows you how to create a database with a table that contains an XML column.
In the tutorial, you store XML data in a table that contains a table with a column of type XML. Follow these steps to create the database and table used in the tutorial:
- Create a database called XMLTUT by issuing
the following command:
CREATE DATABASE xmltut~
By default, databases use the UTF-8 (Unicode) code set. If you choose to store XML data in a database with a code set other than UTF-8, it is best to insert this data in a form that does not undergo code page conversion, such as BIT DATA, BLOB, or XML. To block the use of character data types during XML parsing, preventing possible character substitution from occurring, set the ENABLE_XMLCHAR configuration parameter to NO.
- Connect to the database:
CONNECT TO xmltut~
- Create a table named Customer that contains an XML column called
INFO:
CREATE TABLE Customer (Cid BIGINT NOT NULL PRIMARY KEY, Info XML)~
A primary key is not required to store or index XML data.
You can also add one or more XML columns to a table by using the ALTER TABLE SQL statement.