Home | Previous Page | Next Page   Object-Relational Databases > Understanding Type and Table Inheritance in Dynamic Server > Table Inheritance >

Adding a New Table to a Table Hierarchy

After you define a table hierarchy, you cannot use the ALTER TABLE statement to add, drop, or modify columns of a table within the hierarchy. However, you can add new subtypes and subtables to an existing hierarchy provided that the new subtype and subtable do not interfere with existing inheritance relationships. Figure 33 illustrates one way that you might add a type and corresponding table to an existing hierarchy. The dashed lines indicate the added subtype and subtable.

Figure 33. Example of How You Might Add a Subtype and Subtable to an Existing Inheritance Hierarchy
begin figure description - Two hierarchies of four items each are shown side-by-side. One is the type hierarchy and the other is the table hierarchy. In the hierarchies parents are on top of children.  The type hierarchy is, from top to bottom: "person_t", "employee_t", "sales_rep_t", and "us_sales_rep_t". The inheritance arrow going from "sales_rep_t" to "us_sales_rep_t" is a dotted line. The rectangle around "us_sales_rep_t" is made of dotted lines.  The table hierarchy is, from top to bottom: "person", "employee", "sales_rep", and "us_sales_rep". The inheritance arrow going from "sales_rep" to "us_sales_rep" is a dotted line. The rectangle around "us_sales_rep" is made of dotted lines. There are two directional arrows matching each item in the type hierarchy to exactly one item in the table hierarchy. "person_t" is matched with "person". "employee_t" is matched with "employee". "sales_rep_t" is matched to "sales_rep". "us_sales_rep_t" is matched to "us_sales_rep". - end figure description

The following statements show how you might add the type and table to the inheritance hierarchy that Figure 33 shows:

CREATE ROW TYPE us_sales_rep_t (domestic_sales DECIMAL(15,2)) 
UNDER employee_t;

CREATE TABLE us_sales_rep OF TYPE us_sales_rep_t
UNDER sales_rep;

You can also add subtypes and subtables that branch from an existing supertype and its parallel supertable. Figure 34 shows how you might add the customer_t type and customer table to existing hierarchies. In this example, both the customer table and the employee table inherit properties from the person table.

Figure 34. Example of Adding a Type and Table Under an Existing Supertype and Supertable
begin figure description - Two hierarchies of three items each are shown side-by-side. One is the type hierarchy and the other is the table hierarchy. In the hierarchies parents are on top of children.  The type hierarchy is, from top to bottom: "person_t", "employee_t", and "sales_rep_t". "customer_t" is also present. It is in a dotted rectangle. There is also a dotted inheritance arrow going from "person_t" to "customer_t". A dotted inheritance arrow points down from "customer_t" to show that it might have other children that are not shown.  The table hierarchy is, from top to bottom: "person", "employee", and "sales_rep".  "customer" is also present. It is in a dotted rectangle. There is also a dotted inheritance arrow going from "person" to "customer". A dotted inheritance arrow points down from "customer" to show that it might have other children that are not shown. - end figure description

The following statements create the customer_t type and customer table under the person_t type and person table, respectively:

CREATE ROW TYPE customer_t (cust_num INTEGER) UNDER person_t;

CREATE TABLE customer OF TYPE customer_t UNDER person;
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]