简体   繁体   English

在列数据库设计方法中存储多个值

[英]storing multiple values in column db design approach

I need have a table with columns -> hotel_id, hotel_name, price_per_night, facilities, preferred 我需要一个带有以下列的表-> hotel_id,hotel_name,price_per_night,设施,首选

In this columns facilities and preferred may have multiple values. 在此列中,优选设施可能具有多个值。

For example-> 例如->

facilities can be swimming pool, spa etc.(many diff values can be added with time) 设施可以是游泳池,水疗中心等(可以随时间添加许多差异值)

preferred can be couples, family etc.(many diff values can be added with time) 首选可以是情侣,家庭等(可以随时间添加许多差异值)

I am pretty new to mysql. 我是mysql的新手。 I am confused how to design my database and thought of following approaches -> 我很困惑如何设计数据库并想到以下方法->

  1. To have a multiple values in a single column (which is a bad idea) 在单个列中具有多个值(这是个坏主意)

  2. To create three tables -> 创建三个表->

    a.first would be hotel_main with columns hotel_id, hotel_name, price_per_night a.first将是hotel_main,其列为hotel_id,hotel_name,price_per_night

    b.second would be facilities_hotel with hotel_id, hotel_name, facility b.second是带有hotel_id,hotel_name,设施的Facilities_hotel

    c.third would be preferred_hotel with hotel_id, hotel_name, preferred c.third将是带有hotel_id,hotel_name,preferred的preferred_hotel

I would like to have more suggestions on how to design my database. 我想对如何设计数据库有更多建议。

In general non-1NF designs are bad ideas in transactional processing systems. 通常,非1NF设计在事务处理系统中是个坏主意。 You run into lots of update/delete integrity problems which are hard to solve and MySQL doesn't give you even the tools to make inserts safe. 您遇到许多难以解决的更新/删除完整性问题,MySQL甚至都没有提供使插入安全的工具。

Where people use non-1NF designs effectively these usually meet two criteria: 人们有效地使用非1NF设计时,这些条件通常满足两个条件:

  1. They are always analytical platforms, and 它们始终是分析平台,并且
  2. The data either tolerates degraded integrity or is seldom updated/deleted. 数据要么容忍完整性下降,要么很少更新/删除。

Outside cases where both is true don't even think about breaking 1NF. 在两种情况都成立的外部情况下,甚至不要考虑破坏1NF。 Even where both are true, that's not enough to decide to go that way. 即使两者都是正确的,这仍然不足以决定采取这种方式。

So go with your second approach 所以第二种方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM