(4.2)测试应用程序使用数据库Schema的方式;

  (4.3)检验数据迁移的有效性;

  许多数据库重构技术要求迁移源数据,比如将数据值Customer.Balance复制到Account.Balance,需要检验每位顾客的正确余额确实进行了拷贝。

  (4.4)测试外部程序代码。

  ● 修改数据库Schema;

  以上面的例子,需要加入Account.Balance列和两个触发器:SynchronizeAccountBalance和SynchronizeCustomerBalance。

  完成此事的DDL代码:

ALTER TABLE Account ADD Balance Numeric;
COMMENT ON Account.Balance 'Move of Customer.Balance column, finaldate=2006-06-14';
CREATE OR REPLACE TRIGGER SynchronizeCustomerBalance
  BEFORE INSERT OR UPDATE
  ON Account
  REFERENCE OLD AS OLD NEW AS NEW
  FOR EACH ROW
  DECLARE
  BEGIN
    IF :NEW.Balance IS NOT NULL THEN
      UpdateCustomerBalance;
    END IF
  END;
/
COMMENT ON SynchronizeCustomerBalance 'Move of Customer.Balance column to Account,
dropdate = 2006-06-14';
CREATE OR REPLACE TRIGGER SynchronizeAccountBalance
  BEFORE INSERT OR UPDATE OR DELETE
  ON Customer
  REFERENCE OLD AS OLD NEW AS NEW
  FOR EACH ROW
  DECLARE
  BEGIN
    IF DELETING THEN
      DeleteCustomerIfAccountNotFound;
    END IF
    IF (UPDATING OR INSERTING) THEN
      IF :NEW.Balance IS NOT NULL THEN
        UpdateAccountBalanceForCustomer;
      END IF;
    END IF;
  END;
/
COMMENT ON SynchronizeAccountBalance 'Move of Customer.Balance column to Account, dropdate=2006-06-14'