Database design - boolean attribute or new table

后端 未结 4 1827
太阳男子
太阳男子 2021-01-20 17:53

Let\'s say I have a database table that I want to filter based on a boolean attribute (for example, \"flagged\" attribute). Is it better to just add a \"flagged\" attribute

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 18:40

    It depends. I myself prefer adding a new table when the value is not really related to the table/relation.

    A good example of this is when you have table representing orders and you want to keep track of which ones has been printed. I would add new table called printed_orders with a foreign key to the order.

    create table printed_orders (
      order_id int primary key references order(order_id)
    );
    

    If its been printed or not is not really part of the order but part of the system/business rules.

提交回复
热议问题