adding CHECK to impose constraints on more than one table

后端 未结 4 1676
我在风中等你
我在风中等你 2021-01-29 02:57

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\'

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-29 03:40

    To ensure that a manager actually works in the store, I would do this:

    drop table manages;
    
    alter table works_at
    add column isManager bit default 0;
    

    Ensuring that every store stocks every product is best done with a trigger, as mentioned in the other answers.

    You should also consider the following points.

    1. char(5) is not necessarily the best datatype for primary key fields
    2. Having the employee number as the primary key might not be such a good idea. In real life there could be transfers, or someone might work part time at more than one store.
    3. If every store is supposed to stock every item, the stocks table might not be useful. An inventory table, which include quantity on hand might be better.

提交回复
热议问题