Previous Topic: Example 4Next Topic: Example 6


Example 5

Prevent the acceptance of orders from customers who do not pay their bills by ensuring that any order accepted comes from a customer whose name is on a "customers in good standing" list.

  1. Table containing customers in good standing: PAYING_CUSTOMERS
  2. Table to be protected: ORDERS
  3. Columns on which a match is required:

    ORDERS.CUSTOMER_NAME to PAYING_CUSTOMERS.COMPANY_NAME

  4. Constraint name: ORDERS_TO_PAYING_CUST_NAME
     EXEC SQL
          ALTER TABLE ORDERS ADD FOREIGN KEY
             (CUSTOMER_NAME) REFERENCES PAYING_CUSTOMERS(COMPANY_NAME)
             CONSTRAINT ORDERS_TO_PAYING_CUST_NAME
     END-EXEC