Creating spatial columns

You must create spatial columns to store and retrieve spatial data. After you choose a coordinate system and determine which spatial reference system to use for your data, you create a spatial column in an existing table or import spatial data into a new table.

Before you begin

Before you create a spatial column, your user ID must hold the authorizations that are needed for the Db2 SQL CREATE TABLE statement or ALTER TABLE statement.

Procedure

To create spatial columns:

Use one of the following approaches:
  • For a new table, issue the CREATE TABLE statement to create the table and to include a spatial column within that table.
  • For an existing table, issue the ALTER TABLE statement to add a spatial column.
  • If you are importing spatial data from a shape file, use the SYSPROC.ST_import_shape stored procedure to create a table and to provide this table with a column to hold the data.

Example

The following example shows how to create a table with a spatial column by using the CREATE TABLE statement:
CREATE TABLE CUSTOMERS ( ..., LOCATION DB2GSE.ST_POINT, ...) ;
This next example shows how to add a spatial column to an existing table by using the ALTER TABLE statement:
ALTER TABLE BRANCHES ADD COLUMN LOCATION DB2GSE.ST_POINT;

What to do next

Next, you register the spatial column.