如何在 Nermalization 中跟踪更改并存储计算内容?
我正在尝试创建一个像这样的表:
lives_with_owner_no from until under_the_name
1 1998 2002 1
3 2002 NULL 1
2 1997 NULL 2
3 1850 NULL 3
3 1999 NULL 4
2 2002 2002 4
3 2002 NULL 5
它是 Nermalization 示例,其中我猜是很受欢迎的。
无论如何,我认为我应该在 MySQL 中为 from
挂起对 lives_with
表或 cat_name
表的更改设置依赖关系,然后在 until
和 from
列之间设置依赖关系。我想主人可能想来更新猫的信息,并覆盖“来自”列,所以我必须使用 PHP?有没有什么特殊的方法可以在覆盖上添加时间戳(例如,$date = date("Ymd H:i:s");)?如何在 MySQL 中设置依赖关系?
我还有一个列,可以通过将其他列添加在一起来生成。我想使用 cat 示例,它看起来像:
combined_family_age family_name
75 Alley
230 Koneko
132 Furrdenand
1,004 Whiskers
我应该通过 PHP 添加,然后通过查询输入值,还是应该使用 MySQL 来管理添加?我应该为此使用特殊引擎,例如 MemoryAll 吗?
I'm trying to create a table like this:
lives_with_owner_no from until under_the_name
1 1998 2002 1
3 2002 NULL 1
2 1997 NULL 2
3 1850 NULL 3
3 1999 NULL 4
2 2002 2002 4
3 2002 NULL 5
It's the Nermalization example, which I guess is pretty popular.
Anyway, I think I am just supposed to set up a dependency within MySQL for the from
pending a change to the lives_with
table or the cat_name
table, and then set up a dependency between the until
and from
column. I figure the owner might want to come and update the cat's info, though, and override the 'from' column, so I have to use PHP? Is there any special way I should do the time stamp on the override (for example, $date = date("Y-m-d H:i:s");
)? How do I set up the dependency within MySQL?
I also have a column that can be generated by adding other columns together. I guess using the cat example, it would look like:
combined_family_age family_name
75 Alley
230 Koneko
132 Furrdenand
1,004 Whiskers
Should I add via PHP and then input the values with a query, or should I use MySQL to manage the addition? Should I use a special engine for this, like MemoryAll?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在两个方面不同意正常化的例子。
我将按如下方式设计此数据库:
因此,您将拥有如下数据:
我将使用比年份更细粒度的日期类型(在归一化示例中,将 2002-2002 作为范围确实会导致混乱的查询语法),以便您可以提出诸如
select cat_id fromowner where '2000-06-02' between valid_from 和 valid_to
之类的查询。至于如何在一般情况下处理时态数据的问题:有一本关于该主题的优秀书籍,“用 SQL 开发面向时间的数据库应用程序”,作者:Richard Snodgrass (由 Richard Snodgrass 分发的免费全文 PDF),我相信甚至可以合法下载为 pdf,Google 会帮助您与此。
你的另一个问题:你可以在外部的sql中处理combined_family_age,或者,如果经常需要该列,可以使用视图。不过,您不应该手动管理内容,而是让数据库为您计算。
I disagree with the nermalization example on two counts.
I would design this database as follows:
So you would have data like:
I would use a finer grained date type than just year (in the nermalization example having 2002-2002 as a range can really lead to messy query syntax), so that you can ask queries like
select cat_id from owner where '2000-06-02' between valid_from and valid_to
.As for the question of how to deal with temporal data in the general case: there's an excellent book on the subject, "Developing Time-Oriented Database Applications in SQL" by Richard Snodgrass (free full-text PDF distributed by Richard Snodgrass), which i believe can even be legally downloaded as pdf, Google will help you with that.
Your other question: you can handle the combined_family_age either in sql externally, or, if that column is needed often, with a view. You shouldn't manage the content manually though, let the database calculate that for you.