Create a table to keep track of customers who pay their bills on time. Then create another table to keep track of current orders. Design the tables to enforce the following business rules:
Note: The following example is intended to show the specification of as many different data types and options as possible. For this reason, proper data base design and table normalization have been ignored. Proper design and normalization of your databases is imperative for maximum system performance.
EXEC SQL
CREATE TABLE ACCOUNTING.PAYING_CUSTOMERS
(TOTAL_NUM_ORDERS INTEGER NOT NULL,
FIRST_ORDER DATE,
LAST_ORDER DATE,
COMPANY_NAME CHAR(40) NOT NULL,
TOTAL_GROSS_ORDERS DECIMAL(12,2) NOT NULL,
AVG_GROSS_PER_ORDER DECIMAL(9,2) NOT NULL,
PRIMARY KEY (COMPANY_NAME));
END-EXEC
(Example 5 continued on next page)
EXEC SQL
CREATE TABLE ORDERS
(ORDER_ID_NUMBER INTEGER NOT NULL PRIMARY KEY,
CUSTOMER_NAME CHAR(40) DEFAULT 'INTERNAL ORDER',
SHIPMENT_ID_NUMBER DECIMAL(6,0) NOT NULL UNIQUE,
GROSS_AMOUNT NUMERIC(8,2) NOT NULL,
PERCENT_DOWN_PMT REAL DEFAULT 100.0
CHECK (PERCENT_DOWN_PMT >= 25.0),
NUM_PAYMENTS SMALLINT DEFAULT NULL,
INTEREST_RATE DOUBLE PRECISION CHECK (INTEREST_RATE >= 11.0)
CONSTRAINT ORDERS_MIN_INTEREST_RATE,
DATE_PROMISED DATE,
TIME_PROMISED TIME,
DATE_AND_TIME_SHIPPED TIMESTAMP NOT NULL WITH DEFAULT,
AVG_ITEM_QUANTITY FLOAT,
AVG_NUM_ITEMS FLOAT(6),
TOTAL_PIECES INTEGER NOT NULL WITH DEFAULT,
FOREIGN KEY (CUSTOMER_NAME) REFERENCES
ACCOUNTING.PAYING_CUSTOMERS(COMPANY_NAME),
CHECK (GROSS_AMOUNT > 1000.0 OR PERCENT_DOWN_PMT = 100.0)
CONSTRAINT ORDERS_MIN_AMT_FINANCED);
END-EXEC
How the Tables Enforce the Business Rules:
The following numbers correspond to the numbers of the business rules specified at the beginning of this example.
|
Copyright © 2014 CA.
All rights reserved.
|
|