doushenmao9036 2014-12-15 13:48
浏览 47
已采纳

MySQL在更改条目时优化数据库中的数据存储

We faced with a problem:

When we are generating accounts (or other documents), we use customer (employee) data. However, customers can change their data (e.g. woman get married and her last name changed, or she moved to live in other country and her address changed).

We need, that after editing woman last name, accounts remain with old last name until specific date,and after that specific date, use woman new last name.

e.g. We have a woman: Emily Smith. She married 2014 December 15, and her last name become Brown. Before: December 15 we generate her account with Smith last name but after December 15 we need to generate her account with Brown last name. So in database we need to save both her last names.

How to save entry optimized with only one or a few changed attributes?

P.S. We also need to save the date when the change was made in order to know which last name to use, old or new.

  • 写回答

2条回答 默认 最新

  • dongpian6319 2014-12-15 13:55
    关注

    This is called a slowly changing dimensions. The traditional approach is to have records with an effective date and end date attached. So, Emily would have two rows in this table:

    AccountId    Firstname     LastName     EffDate      EndDate
       1           Emily       Smith        2001-01-01   2014-12-14
       1           Emily       Brown        2014-12-15   NULL
    

    Often, the NULL value for the current record would be some arbitrary date far in the future (such as 9999-12-31). Not having to deal with NULLs in the logic can improve perfromance.

    Then, when you want the record as of a particular date, you just use the record that is valid on that date. If you want the current record, the same logic holds -- find the record valid today.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类