home *** CD-ROM | disk | FTP | other *** search
- % Add a region column to sales_order_items so the
- % table can be partitioned by region.
-
- ALTER TABLE sales_order_items ADD region CHAR(7);
-
- % Set new region column for existing sales_orders.
-
- UPDATE sales_order_items
- SET region = ( SELECT region FROM sales_order
- WHERE sales_order_items.id = sales_order.id );
-
- % Create triggers to automatically maintain the new region column
- % so that applications do not need to be aware of it.
-
- CREATE TRIGGER set_order_item_region BEFORE INSERT
- ON sales_order_items
- REFERENCING NEW AS new_item
- FOR EACH ROW
- BEGIN
- SET new_item.region = ( SELECT region FROM sales_order
- WHERE sales_order.id = new_item.id )
- END;
-
- CREATE TRIGGER update_order_items_region AFTER UPDATE OF region
- ON sales_order
- REFERENCING NEW AS new_order
- FOR EACH ROW
- BEGIN
- UPDATE sales_order_items SET region=new_order.region
- WHERE sales_order_items.id=new_order.id
- END;
-
- % Add a default value for fin_code_id column because the fin_code
- % table is not included in the publication.
-
- ALTER TABLE sales_order MODIFY fin_code_id DEFAULT 'r1';
-
- % Create a publication that includes 5 tables:
- % - the complete customer and product tables
- % - sales_order and sales_order_items subscribed by region
- % - selected columns from the employee table
-
- CREATE PUBLICATION sales(
- TABLE customer,
- TABLE product,
- TABLE sales_order SUBSCRIBE BY region,
- TABLE sales_order_items SUBSCRIBE BY region,
- TABLE employee(emp_id,emp_fname,emp_lname,dept_id) WHERE dept_id=200);
-
- % Set up userids for replication.
-
- CREATE REMOTE TYPE FILE ADDRESS 'COMPANY';
- GRANT PUBLISH TO "dba";
- GRANT CONNECT TO east IDENTIFIED BY east;
- GRANT REMOTE TO east TYPE FILE ADDRESS 'east';
-
- % Create a subscription for the eastern sales office.
-
- CREATE SUBSCRIPTION TO sales('Eastern') FOR east;
-