我想修改以下DDL以添加CHECK约束,以便商店的经理(FK employee_number是商店表)在同一商店(员工表中的FK store_code)工作,并且商店提供所有产品,如果它类型是'本地'。
有人可以帮忙吗?
CREATE TABLE employee(
employee_number CHAR(5) NOT NULL,
name VARCHAR(30),
store_code CHAR(5)
PRIMARY KEY(employee_number),
FOREIGN KEY(store_code) REFERENCES store
)
CREATE TABLE store(
store_code CHAR(5) NOT NULL,
type VARCHAR(15),
employee_number CHAR(5),
PRIMARY KEY(store_code),
FOREIGN KEY(employee_number) REFERENCES employee
)
CREATE TABLE product(
product_code CHAR(5) NOT NULL,
description VARCHAR(150),
cost DEC(10,2),
PRIMARY KEY(product_code)
)
CREATE TABLE stocks(
store_code CHAR(5) NOT NULL,
product_code CHAR(5) NOT NULL,
PRIMARY KEY(product_code, store_code),
FOREIGN KEY(product_key) REFERENCES product,
FOREIGN KEY(store_code) REFERENCES store
)