数据库设计 - 存储模板和实例的最佳方式

发布于 2024-10-18 02:24:33 字数 187 浏览 1 评论 0原文

我们的数据库要求拥有模板,例如拥有一个会议模板,其中包含参加会议的特定人群以及基本会议名称。然后可以“实例化”会议,以便您可以复制该会议并修改属性。我能想到的最好方法是:

  1. 将“实例”存储在同一个表中,并类似地存储相关信息。
  2. 创建具有相同属性的不同表,并将模板存储在一个表中,将“实例”存储在另一表中。

Our database calls for having templates, for instance having a meeting template with a certain group of people who attend the meeting along with a base meeting name. The meeting can then be "instantiated" so that you can make copies of that meeting and modify the attributes. The best ways I can think of doing it are to:

  1. Store the "instances" in the same table and store related information similarly.
  2. Make different tables with the same attributes and store the templates in one table and the "instances" in another table.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔小萌 2024-10-25 02:24:33

我会将模板存储在一个单独的表中,该表镜像实例表中的必要列。这样,在查找特定类型的数据时,您不需要在任何地方放置特殊逻辑来过滤掉一种或另一种类型(模板或实例)。将模板放入另一个表中将允许您在将来需要时向模板添加更多元数据。

I would store the templates in a separate table that mirrors the necessary columns in the instance table. That way, you won't need to put special logic anywhere to filter out one or the other type (template or instance) when looking for a specific type of data. Putting the templates in another table will allow you to add more metadata to the template if you need to in the future.

猫弦 2024-10-25 02:24:33

如何使用一个表,但向表中添加一个诸如“isTemplate”之类的标志字段,该字段将用于将记录标识为默认记录或“模板”记录。

您创建一个具有默认参数的新记录,并将 isTemplate 设置为“1”或 TRUE 或 YES 或其他。

创建新会议时,只需创建模板的副本,如下所示:

INSERT INTO meetings(place,people,time)
(SELECT place,people,time FROM meetings WHERE isTemplate = '1')

如果您有多个模板,那么您将获得可用模板的列表,如下所示:

SELECT * FROM meetings WHERE isTemplate = '1'

然后通过主键实例化其中一个模板,而不是比“isTemplate”:

INSERT INTO meetings(place,people,time)
(SELECT place,people,time FROM meetings WHERE ID = 'xxxx')

How about using one table, but adding a flag field like "isTemplate" to the table, which will serve to identify a record as the default or 'template' record.

You create a new record which has the default parameters, and set isTemplate as "1" or TRUE or YES or whatever.

When creating a new meeting, then just create is as a copy of the template, like so:

INSERT INTO meetings(place,people,time)
(SELECT place,people,time FROM meetings WHERE isTemplate = '1')

If you have multiple templates, then you will get a list of the available templates as:

SELECT * FROM meetings WHERE isTemplate = '1'

and then instantiate one of those templates by the primary key rather than 'isTemplate':

INSERT INTO meetings(place,people,time)
(SELECT place,people,time FROM meetings WHERE ID = 'xxxx')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文