简体   繁体   English

规范化数据库的大量数据

[英]Normalizing large amount of data for database

I have a large amount of data I need to store in a database. 我需要存储在数据库中的大量数据。 The data is: for every day of the month, there are 5 events. 数据是:对于每月的每一天,有5个事件。 The 5 events are further split into 2 different sub-events which need to be kept separate, meaning for every day of the month, there are 10 events. 5个事件进一步分为2个不同的子事件,需要保持独立,这意味着每月的每一天都有10个事件。

At the top level, the 5 events have different headings and lower down, the odd numbered sub-events have one heading and the even numbered sub-events have one heading. 在顶层,5个事件具有不同的标题和下部,奇数子事件具有一个标题,偶数子事件具有一个标题。

I'd like to normalize this data before storing but I'm struggling to come to a final db structure and am looking for hints on this. 我想在存储之前对这些数据进行规范化,但是我很难找到最终的数据库结构并正在寻找这方面的提示。 I have very little experience with normalization (this is for a personal project I'm working on) but I'd rather do it properly then dump everything into the db in one go. 我对规范化的经验很少(这是我正在进行的个人项目),但我宁愿正确地做,然后一次性将所有内容都转储到数据库中。

Edit: Example of data as requested: 编辑:请求的数据示例:

20th March: 3月20日:

Event 1: Sub-event 1: 4:30am, Sub-event 2: 5:00am 活动1:分项赛事1:凌晨4:30,分项赛事2:上午5:00
Event 2: Sub-event 1: 12:30pm, Sub-event 2: 1:00pm 活动2:分项赛事1:12:30 pm,分项赛事2:下午1:00
Event 3: Sub-event 1: 4:15pm, Sub-event 2: 4:45pm 事件3:子事件1:下午4:15,子事件2:下午4:45
Event 4: Sub-event 1: 6:15pm, Sub-event 2: 6:45pm 事件4:子事件1:下午6:15,子事件2:下午6:45
Event 5: Sub-event 1: 8:00pm, Sub-event 2: 8:45pm 事件5:子事件1:晚上8:00,子事件2:晚上8:45

All the events repeat at varying times throughout the month and entire year. 所有事件在整个月和整年的不同时间重复。

Just have an event table with a row for each event. 只需要一个事件表,每个事件都有一行。 Subevent can have a foreign key to the same event to reference the event of which they are subevents. Subevent可以使用同一事件的外键来引用它们是子事件的事件。

Here is a simple model to achieve what you are looking for. 这是一个简单的模型,可以实现您的目标。 Depending on how you will be using this data you can add Alternate Keys or modify the Primary Keys as you see fit. 根据您使用此数据的方式,您可以根据需要添加备用键或修改主键。 Let me know if you have any questions. 如果您有任何疑问,请告诉我。

在此输入图像描述

EDIT in response to comment: 编辑回应评论:

Not exactly sure if I understand what you are asking for. 不确定我是否明白你的要求。 Here would be the details though. 这里有细节。 The relationships between the tables are defined in the model. 表之间的关系在模型中定义。 If you don't understand (forgive me if you do) the model I would recommend looking up ER Diagrams utilizing Crow's Foot Notation. 如果您不理解(请原谅我)模型,我建议使用Crow's Foot Notation查找ER图。

EventId (INT) : Incremental 
EventTypeCode (CHAR (2)) : Used to cover Events 1-5 as E1 - E5
Description (VARCHAR) : Info describing E1-E5
SubEventId (boolean) : Since you only declare two options 1 & 2

Hope this helps. 希望这可以帮助。

These tables normalise the data: 这些表规范化数据:

   Event
      Date 
      Time
      Event Type (FK to Event Type)
      PK Date,Time,Event Type
      *Example Data: 2011-03-30; 04:30; 1 top;*

    Event Type 
      Type 
      Heading
      PK Type (Values 1(top)-5(top),1(odd)-5(even))
      *Example Data: 1 top; This is event type 1 top level;*

    Parent Event
      Child Event (FK to Event)
      Parent Event (FK to Event) 
      PK Child Event, Parent Event (and possibly Index each field independently)
      *Example Data: 2011-03-30, 04:30, 1top; 2011-03-31, 05:00, 1 even;*

EDIT: As requested example data added. 编辑:根据要求添加示例数据。 The relationships are given by the foreign keys (FK), so the example is relating one top level event to one sub-event of typ 1 even. 关系由外键(FK)给出,因此该示例将一个顶级事件与典型1的一个子事件相关联。

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

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