I need to generate data based on a table that is supertype/subtypes. Example of table as follows:
DROP TABLE employees_tp;
CREATE TABLE employees_tp(
emp_id_pk INTEGER NOT NULL,
badge_no DECIMAL(3,0) NOT NULL,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
employee_type CHAR(1) NOT NULL,
stock_option CHAR(1),
car_allowance CHAR(1),
profit_sharing CHAR(1),
contract_no VARCHAR(9)
);
ALTER TABLE employees_tp
ADD CONSTRAINT emp_employee_type_ck
CHECK ( employee_type IN (βEβ, βTβ, βSβ) );
ALTER TABLE employees_tp
ADD CONSTRAINT emp_employee_options_ck
CHECK (
(
(employee_type = βEβ AND stock_option = βYβ)
AND ( profit_sharing IS NULL )
AND ( contract_no IS NULL )
)
OR
(
(employee_type = βTβ AND profit_sharing = βYβ)
AND ( stock_option IS NULL )
AND ( car_allowance IS NULL )
AND ( contract_no IS NULL )
)
OR
(
(employee_type = βSβ AND contract_no = βYβ)
AND ( stock_option IS NULL )
AND ( car_allowance IS NULL )
AND ( profit_sharing IS NULL )
)
);
INSERT INTO employees_tp VALUES
(1, 101, βJoeβ, βBatesβ, βEβ, βYβ, βYβ, NULL, NULL),
(2, 101, βSallyβ, βJonesβ, βEβ, βYβ, NULL, NULL, NULL),
(3, 103, βPeteβ, βSmithβ, βTβ, NULL, NULL, βYβ, NULL);