I want to modify the following DDL to add CHECK constraints so that the manager of a store works at the same store and a store supplies all the products if its type is \'local\'
I see options though the implementation changes depending on the RDBMS:
You will have to create your function, and then utilize it when creating the constraint.
Examples/Sources:
In addition to the proposed solution with triggers, another option is to create a stored procedure that is used to insert the data.
The stored procedure performs the validation, and it the conditions are not met does not insert the data.
The below would ensure that a manage entry is not added unless an employee works at the specific store.
INSERT INTO manager (emploee_number, store_code) AS
SELECT distinct employee_number,
store_code
FROM manages
WHERE store_code = INPUT_STORE_CODE
AND employee_number = INPUT_EMPLOYEE_NUMBER