Colocating Related Rows from Multiple Tables

The COLOCATE WITH clause specifies the tables with which the partitioned table must be colocated.

Note: Tables that are referenced in the COLOCATE WITH clause must exist at the time you create the partitioned table.

When two tables are partitioned on columns and colocated, it forces partitions having the same values for those columns in both tables to be located on the same SQLFire member. For example, with range or list partitioning, any rows that satisfy the range or list are colocated on the same member for all the colocated tables.

When you specify the COLOCATE WITH clause, you must use the PARTITION BY clause to specify partition columns in the target tables in the same order using the same partitioning strategy (for example, with identical ranges). The columns must also be of the same type, not considering constraints. Any REDUNDANCY or BUCKETS clause must also be the same as the tables with which it is colocated.

Note: In order for two partitioned tables to be colocated, the SERVER GROUPS clauses in both CREATE TABLE statements must be identical. In order for two replicated tables to be colocated, both tables must specify the same server groups or one table's server groups must be a subset of the other table's server groups.
For example, if you create the partitioned table, "countries," as follows:
CREATE TABLE COUNTRIES 
( 
  COUNTRY VARCHAR(26) NOT NULL CONSTRAINT COUNTRIES_UNQ_NM Unique, 
  COUNTRY_ISO_CODE CHAR(2) NOT NULL CONSTRAINT COUNTRIES_PK PRIMARY KEY, 
  REGION VARCHAR(26), 
  CONSTRAINT COUNTRIES_UC
    CHECK (country_ISO_code = upper(country_ISO_code) ) 
) PARTITION BY PRIMARY KEY
You can colocate another table, "cities," using the command:
CREATE TABLE CITIES 
( 
  CITY_ID INTEGER NOT NULL CONSTRAINT CITIES_PK Primary key,
  CITY_NAME VARCHAR(24) NOT NULL, 
  COUNTRY VARCHAR(26) NOT NULL, 
  AIRPORT VARCHAR(3), 
  LANGUAGE VARCHAR(16), 
  COUNTRY_ISO_CODE CHAR(2) CONSTRAINT COUNTRIES_FK 
  REFERENCES COUNTRIES (COUNTRY_ISO_CODE) 
) PARTITION BY COLUMN (COUNTRY_ISO_CODE) 
  COLOCATE WITH (COUNTRIES)

In this example, both "countries" and "cities" are partitioned using the COUNTRY_ISO_CODE column. Rows with the same COUNTRY_ISO_CODE value are colocated on the same SQLFire members.

See the CREATE TABLE reference page for more information.