0

I want to modify the following DDL to add CHECK constraints so that the manager of a store(FK employee_number is store table) works at the same store (FK store_code in employee table table) and a store supplies all the products if its type is 'local'.

Can anyone help?

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
  )
zan
  • 355
  • 6
  • 16

1 Answers1

0

you could use a trigger to realize this

you can look at this question for an example Throw an error in a MySQL trigger

Community
  • 1
  • 1
cproinger
  • 2,258
  • 1
  • 17
  • 33