简体   繁体   English

MySQL中具有两个以上维度的表

[英]Tables in MySQL with more than two dimensions

I am an beginner-to-intermediate level programmer and am trying to re-design a MySQL database for someone. 我是初学者到中级的程序员,我正在尝试为某人重新设计一个MySQL数据库。 It has the following attributes: 它具有以下属性:

  • Shows start and end times for alcohol sales in an area 显示某个区域的酒精销售的开始和结束时间
  • Times vary by day of week 时间因星期几而异
  • Times vary for beer and wine vs. all types of alcohol (liquor, too). 啤酒和葡萄酒的时间因所有类型的酒精(酒也是如此)而异。
  • Times vary by off-premises (ie: liquor store) vs. on-premises (ie: bar) 外部(即:酒类商店)与内部部署(即:酒吧)的时间有所不同

I tried researching this but couldn't find a clear answer. 我试过研究这个但是找不到明确的答案。 Currently he one huge table. 目前他是一张巨大的桌子。 Example columns are: 示例列是:

  • offwedbwstart (off-premises, Wednesday, beer & wine only, starting time) offwedbwstart(场外,周三,仅啤酒和葡萄酒,开始时间)
  • onfriallend (on-premises, Friday, all alcohol types, end time) onfriallend(内部部署,周五,所有酒类型,结束时间)

I'm wondering if there isn't a better way to organize this table using arrays as entries or by using multiple tables. 我想知道是否没有更好的方法来组织此表使用数组作为条目或使用多个表。 Does anyone have any ideas? 有没有人有任何想法? Or is this simply a matter of preference? 或者这只是一个偏好问题? I'm also worried about the efficiency of using multiple tables. 我也担心使用多个表的效率。

Thank you! 谢谢!


Revision in response to comment (more detailed explanation): 修改以回应评论(更详细的解释):

Here's are the fields of the original table which I'm tasked with revising. 这是原始表格中我负责修改的字段。 It is all one big table: 这是一张大桌子:

id BIGINT(9) NOT NULL, - Primary Key id BIGINT(9)NOT NULL, - 主键
state TINYTEXT NULL, - Full State Name state TINYTEXT NULL, - 完整州名
county TINYTEXT NULL, - Full County Name county TINYTEXT NULL, - 全县名
place TINYTEXT NULL, - Full Place Name place TINYTEXT NULL, - 完整的地方名称
placetype TINYINT(2) NULL DEFAULT NULL, - Is the Place a County, City, etc. placetype TINYINT(2)NULL DEFAULT NULL, - 放置县,城市等
format TINYINT(1) NULL DEFAULT NULL, - Not sure format TINYINT(1)NULL DEFAULT NULL, - 不确定
multname TINYINT(1) NULL DEFAULT NULL, - Does the place have multiple names multname TINYINT(1)NULL DEFAULT NULL, - 该地点是否有多个名称
multcounty TINYINT(1) NULL DEFAULT NULL, - Does the place cross multiple counties multcounty TINYINT(1)NULL DEFAULT NULL, - 该地点是否跨越多个县
population INT(8) NULL DEFAULT NULL, - Population population INT(8)NULL DEFAULT NULL, - Population
offsunallstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premsies (convenience stores, liquor stores, etc.), Sunday, All types of alcohol (including liquor), Start Time (military time integer, hours and minutes past midnight) offsunallstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premsies(便利店,酒类商店等),星期日,所有类型的酒精(包括酒类),开始时间(军事时间整数,午夜时分和分钟)
offsunallend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Sunday, All types of alcohol, End Time (military time integer, hours and minutes past midnight) offsunallend SMALLINT(4)NULL DEFAULT NULL, - 场外,周日,所有类型的酒精,结束时间(军事时间整数,午夜时分和小时)
offsunbwstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Sunday, Beer and Wine only,Start Time offsunbwstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Sunday,Beer and Wine only,Start Time
offsunbwend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Sunday, Beer and Wine only,End Time offsunbwend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Sunday,Beer and Wine only,End Time
offmonallstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Monday, All types of alcohol, Start Time offmonallstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Monday,所有类型的酒精,开始时间
offmonallend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Monday, All types of alcohol, End Time offmonallend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Monday,所有类型的酒精,结束时间
offmonbwstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Monday, Beer and Wine only,Start Time offmonbwstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Monday,Beer and Wine only,Start Time
offmonbwend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Monday, Beer and Wine only,End Time offmonbwend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Monday,Beer and Wine only,End Time
offtueallstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Tuesday, All types of alcohol, Start Time offtueallstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Tuesday,所有类型的酒精,开始时间
offtueallend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Tuesday, All types of alcohol, End Time offtueallend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Tuesday,所有类型的酒精,结束时间
offtuebwstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Tuesday, Beer and Wine only,Start Time offtuebwstart SMALLINT(4)NULL DEFAULT NULL, - 场外,星期二,仅啤酒和葡萄酒,开始时间
offtuebwend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Tuesday, Beer and Wine only,End Time offtuebwend SMALLINT(4)NULL DEFAULT NULL, - 场外,周二,仅限啤酒和葡萄酒,结束时间
offwedallstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Wednesday, All types of alcohol, Start Time offwedallstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Wednesday,所有类型的酒精,开始时间
offwedallend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Wednesday, All types of alcohol, End Time offwedallend SMALLINT(4)NULL DEFAULT NULL, - 场外,星期三,所有类型的酒精,结束时间
offwedbwstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Wednesday, Beer and Wine only,Start Time offwedbwstart SMALLINT(4)NULL DEFAULT NULL, - 场外,周三,仅啤酒和葡萄酒,开始时间
offwedbwend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Wednesday, Beer and Wine only,End Time offwedbwend SMALLINT(4)NULL DEFAULT NULL, - 场外,周三,仅啤酒和葡萄酒,结束时间
offthuallstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Thursday, All types of alcohol, Start Time offthuallstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Thursday,所有类型的酒精,开始时间
offthuallend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Thursday, All types of alcohol, End Time offthuallend SMALLINT(4)NULL DEFAULT NULL, - 场外,星期四,所有类型的酒精,结束时间
offthubwstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Thursday, Beer and Wine only,Start Time offthubwstart SMALLINT(4)NULL DEFAULT NULL, - 场外,星期四,仅限啤酒和葡萄酒,开始时间
offthubwend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Thursday, Beer and Wine only,End Time offthubwend SMALLINT(4)NULL DEFAULT NULL, - 场外,周四,仅限啤酒和葡萄酒,结束时间
offfriallstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Friday, All types of alcohol, Start Time offfriallstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Friday,所有类型的酒精,开始时间
offfriallend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Friday, All types of alcohol, End Time offfriallend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Friday,所有类型的酒精,结束时间
offfribwstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Friday, Beer and Wine only,Start Time offfribwstart SMALLINT(4)NULL DEFAULT NULL, - 场外,周五,仅啤酒和葡萄酒,开始时间
offfribwend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Friday, Beer and Wine only,End Time offfribwend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Friday,Beer and Wine only,End Time
offsatallstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Saturday, All types of alcohol, Start Time offsatallstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Saturday,所有类型的酒精,开始时间
offsatallend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Saturday, All types of alcohol, End Time offsatallend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Saturday,所有类型的酒精,结束时间
offsatbwstart SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Saturday, Beer and Wine only,Start Time offsatbwstart SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Saturday,Beer and Wine only,Start Time
offsatbwend SMALLINT(4) NULL DEFAULT NULL, - Off-Premises, Saturday, Beer and Wine only,End Time offsatbwend SMALLINT(4)NULL DEFAULT NULL, - Off-Premises,Saturday,Beer and Wine only,End Time
onsunallstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies (bars, restaraunts, etc.), Sunday, All types of alcohol, Start Time onsunallstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies(酒吧,餐厅等),星期日,所有类型的酒精,开始时间
onsunallend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Sunday, All types of alcohol, End Time onsunallend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Sunday,所有类型的酒精,结束时间
onsunbwstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Sunday, Beer and Wine only,Start Time onsunbwstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Sunday,Beer and Wine only,Start Time
onsunbwend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Sunday, Beer and Wine only,End Time onsunbwend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Sunday,Beer and Wine only,End Time
onmonallstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Monday, All types of alcohol, Start Time onmonallstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Monday,所有类型的酒精,开始时间
onmonallend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Monday, All types of alcohol, End Time onmonallend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Monday,所有类型的酒精,结束时间
onmonbwstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Monday, Beer and Wine only,Start Time onmonbwstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Monday,Beer and Wine only,Start Time
onmonbwend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Monday, Beer and Wine only,End Time onmonbwend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Monday,Beer and Wine only,End Time
ontueallstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Tuesday, All types of alcohol, Start Time ontueallstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Tuesday,所有类型的酒精,开始时间
ontueallend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Tuesday, All types of alcohol, End Time ontueallend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Tuesday,所有类型的酒精,结束时间
ontuebwstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Tuesday, Beer and Wine only,Start Time ontuebwstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Tuesday,Beer and Wine only,Start Time
ontuebwend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Tuesday, Beer and Wine only,End Time ontuebwend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Tuesday,Beer and Wine only,End Time
onwedallstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Wednesday, All types of alcohol, Start Time onwedallstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Wednesday,所有类型的酒精,开始时间
onwedallend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Wednesday, All types of alcohol, End Time onwedallend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Wednesday,所有类型的酒精,结束时间
onwedbwstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Wednesday, Beer and Wine only,Start Time onwedbwstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Wednesday,Beer and Wine only,Start Time
onwedbwend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Wednesday, Beer and Wine only,End Time onwedbwend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Wednesday,Beer and Wine only,End Time
onthuallstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Thursday, All types of alcohol, Start Time onthuallstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Thursday,所有类型的酒精,开始时间
onthuallend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Thursday, All types of alcohol, End Time onthuallend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Thursday,所有类型的酒精,结束时间
onthubwstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Thursday, Beer and Wine only,Start Time onthubwstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Thursday,Beer and Wine only,Start Time
onthubwend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Thursday, Beer and Wine only,End Time onthubwend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Thursday,Beer and Wine only,End Time
onfriallstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Friday, All types of alcohol, Start Time onfriallstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Friday,所有类型的酒精,开始时间
onfriallend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Friday, All types of alcohol, End Time onfriallend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Friday,所有类型的酒精,结束时间
onfribwstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Friday, Beer and Wine only,Start Time onfribwstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Friday,Beer and Wine only,Start Time
onfribwend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Friday, Beer and Wine only,End Time onfribwend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Friday,Beer and Wine only,End Time
onsatallstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Saturday, All types of alcohol, Start Time onsatallstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Saturday,所有类型的酒精,开始时间
onsatallend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Saturday, All types of alcohol, End Time onsatallend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Saturday,所有类型的酒精,结束时间
onsatbwstart SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Saturday, Beer and Wine only,Start Time onsatbwstart SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Saturday,Beer and Wine only,Start Time
onsatbwend SMALLINT(4) NULL DEFAULT NULL, - On-Premsies, Saturday, Beer and Wine only,End Time onsatbwend SMALLINT(4)NULL DEFAULT NULL, - On-Premsies,Saturday,Beer and Wine only,End Time
offexceptions TEXT NULL, - Off-Premises exceptions as a note offexceptions TEXT NULL, - 作为注释的异常异常
onexceptions TEXT NULL, - On-Premises exceptions as a not onexceptions TEXT NULL, - On-Premises异常为not
source TEXT NULL, - Where did this information come from? source TEXT NULL, - 这些信息来自哪里?
sourcelink TINYTEXT NULL, - Link for information sourcelink TINYTEXT NULL, - 链接信息
timezone TINYTEXT NULL, - TimeZone (EST, for example) timezone TINYTEXT NULL, - TimeZone(例如EST)
notes TEXT NULL - Other miscellaneous notes notes TEXT NULL - 其他杂项说明

As you can see this is kind of a data nightmare. 正如您所看到的,这是一种数据噩梦。 I've been reading up on how to organize this better and some problems that come up are crossing over midnight for sales, and there is another problem of multiple days of the week having the same start and close times, to which I thought I could create a table that simply had the fields: 我一直在阅读如何更好地组织这个问题,并且出现的一些问题正在跨越午夜进行销售,并且还存在另一个问题,即一周中的多天具有相同的开始和关闭时间,我认为我可以创建一个只有字段的表:

  • Start Day (weekday, integer representation) 开始日(工作日,整数表示)
  • End Day (weekday, integer representation) 结束日(工作日,整数表示)
  • Start Time (hours past midnight that morning, integer representation) 开始时间(当天早晨午夜时间,整数表示)
  • End Time (hours past midnight that morning, integer representation) 结束时间(当天早晨午夜时间,整数表示)

Please feel free to make any suggestions for a schema. 请随意为架构提出任何建议。

Thank you! 谢谢!

Using multiple tables is one of the major strengths of using a relational database . 使用多个表是使用关系数据库的主要优势之一。 Otherwise, go ahead and use a spreadsheet program instead. 否则,请继续使用电子表格程序。 :-0 :-0

One flaw I see in that database structure is that finding, for example, Thursday's information requires knowing the specific field name of four fields. 我在该数据库结构中看到的一个缺陷是,例如,查找星期四的信息需要知道四个字段的特定字段名称。 It would be better for the field names to be generic—no day of week in them—and add one field for the day of the week. 最好是字段名称是通用的 - 在它们中没有星期几 - 并且为一周中的某一天添加​​一个字段。 That reduces the number of fields by a factor of almost seven: 28 fields are reduced to 5. 这减少了几乎七倍的字段数:28个字段减少到5个。

There might be some further data normalization possible with the geography fields, but it is tough to know without knowing more about how that is used. 地理学领域可能还有一些可能的数据标准化,但是如果不了解更多关于如何使用的信息,就很难知道。 If there is a lot of interfacing to the field names, you already have a heap of work just to reducing it for day of week. 如果与字段名称有很多接口,那么您已经有一堆工作只是为了减少它在一周中的某一天。 Try revising the schema just for that much and you'll probably know enough to decide if more needs to be done or if it would be more work than it is worth. 尝试修改架构只是为了那么多,你可能已经足够了解是否需要做更多的工作,或者它是否会比它的价值更多。

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

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