如何使用传统关系数据库复制核心数据模型?
我的应用程序使用核心数据和下面的数据模型。但是,我正在切换到具有列和行的标准数据库。谁能帮助我设置这个新的数据库架构?
I have my app using core data with the data model below. However, I'm switching to a standard database with columns and rows. Can anyone help me with setting up this new database schema?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要为每个实体及其属性创建表(请注意,我向每个关系表添加了“id”):
现在您已经有了描述每个实体的表格,您需要创建描述这些实体之间关系的表 - 与之前一样,表名大写,字段位于括号中:
就是这样!现在,如果您需要将练习添加到例程中,您只需:
对于所有其余关系都适用。
注意:您的核心数据模型具有一对多和多对多关系。如果您想明确强制关系是一对多的(例如,Exercise 只能有 1 个例程),那么您需要将“exercise_id”设置为 RoutineExercises 表的索引。如果您希望允许多对多关系(即每个练习允许有多个例程),则将(routine_id,exercise_id)的元组设置为索引。
First of all you need to create tables for each of the Entities and their attributes (note I added "id" to each of the tables for relationships):
Now that you have tables that describe each of the entities, you need to create tables that will describe the relationships between these entities - as before table names are in capitals and their fields are in parenthesis:
That's it! Now if you need to add an exercise to a routine, you simply:
This will hold true for all the rest of the relationships.
NOTE: Your core data model has one-to-many and many-to-many relationships. If you want to specifically enforce that a relationship is one-to-many (e.g. Exercise can only have 1 routine), then you will need to make "exercise_id" as the index for the RoutineExercises table. If you want a many-to-many relationships to be allowed (i.e. each exercise is allowed to have multiple routines), then set the tuple of (routine_id, exercise_id) as the index.