Showing posts with label ORA-14652 in Reference Partitioning in Oracle 11g. Show all posts
Showing posts with label ORA-14652 in Reference Partitioning in Oracle 11g. Show all posts

Wednesday, June 2, 2010

ORA-14652 in Reference Partitioning in Oracle 11g

What I learned today was - a new feature it is Reference Partitioning in Oracle 11g.

Reference partitioning is a new partitioning option in Oracle 11g that allows the partitioning of two related tables to be based on a referential constraint.  In other words, when there is a parent-child relationship between two tables, the parent table can be defined with its partitions.  Subsequently, the child table can be equipartitioned by defining the child table to inherit the partitioning key from the parent table, without the need to duplicate the partition key columns.

scott@11G> create table t(
  2     x number,
  3     y number,
  4     z date ,
  5     constraint t_pk primary key (x)
  6  )
  7  partition by range(z)
  8  (
  9     partition p1 values less than (to_date('01/01/2006','mm/dd/yyyy')),
 10     partition p2 values less than (to_date('02/01/2006','mm/dd/yyyy')),
 11     partition p3 values less than (to_date('03/01/2006','mm/dd/yyyy')),
 12     partition p4 values less than (to_date('04/01/2006','mm/dd/yyyy'))
 13  );

Table created.

scott@11G> create table t1
  2  (
  3     a_c number,
  4     b number,
  5     constraint t1_fk foreign key(a_c) references t(x)
  6  )partition by reference(t1_fk);
)partition by reference(t1_fk)
                        *
ERROR at line 6:
ORA-14652: reference partitioning foreign key is not supported


Referential constraint on child table must be defined on a NOT NULL parent column and a virtual column cannot be part of the partitioning foreign key. Violating any of these limitations will cause an error such as ORA-14652

scott@11G> create table t1
  2  (
  3     a_c number  NOT NULL,
  4     b number,
  5     constraint t1_fk foreign key(a_c) references t(x)
  6  )partition by reference(t1_fk);

Table created. 

scott@11G> SELECT table_name, partition_name, partition_position
  2  FROM user_tab_partitions
  3  WHERE table_name IN('T','T1')
  4  ORDER BY table_name, partition_name
  5  /

TABLE_NAME     PARTITION_NAME        PARTITION_POSITION
-------------------- ------------------------      ------------------
T                              P1                                     1
T                              P2                                     2
T                              P3                                     3
T                              P4                                     4
T1                            P1                                     1
T1                            P2                                     2
T1                            P3                                     3
T1                            P4                                     4

8 rows selected.