来自另一个表的默认列值
如何创建一个表,其中许多列具有来自另一个表的默认值?
例如,我有一个表保存一些数据,然后另一个表保存前一个表的外键,以及可以保存与第一个表类似的数据的列。我希望能够从第一个表创建行的“快照”,其中所有日期都是默认输入的。
谢谢。
How would you create a table where a number of the columns have default values that come from another table?
For example, I have a table that holds some data, and then another table that holds the foreign key for the previous table and columns that can hold similar data to the first table. I want to be able to create a 'snapshot' of rows from the first table where all the date is input be default.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个具体的例子可能会有所帮助。
考虑一个具有一个 FAMILY 实体和一个子 FAMILY_MEMBER 实体的数据模型。某些属性(例如出生日期)是特定于子实体的。其他实体(例如 FAMILY_NAME)可以考虑针对父实体或子实体进行存储。
在某些情况下,您可能决定在 FAMILY 实体上存储一个 FAMILY_NAME,但允许在 FAMILY_MEMBER 实体上进行“覆盖”。在这种情况下,我会将 FAMILY_MEMBER 上的值保留为 NULL。然后,我可能有一个连接两个实体的视图,并具有 NVL(fm.FAMILY_NAME, f.FAMILY_NAME) 派生值。
A concrete example may help.
Consider a data model with one FAMILY entity and a child FAMILY_MEMBER entity. Some attributes, such as date of birth, would be specific to the child entity. Others, such as FAMILY_NAME, could be considered for storage against either the parent or child entity.
In some cases you may decide to store one FAMILY_NAME on the FAMILY entity but allow for a 'overrride' on the FAMILY_MEMBER entity. In this case, I would leave the value on the FAMILY_MEMBER as NULL. I might then have a view that joins the two entities and has an NVL(fm.FAMILY_NAME, f.FAMILY_NAME) derived value.