如何使用传统关系数据库复制核心数据模型?

发布于 2024-12-09 17:36:44 字数 135 浏览 0 评论 0原文

我的应用程序使用核心数据和下面的数据模型。但是,我正在切换到具有列和行的标准数据库。谁能帮助我设置这个新的数据库架构?

在此处输入图像描述

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?

enter image description here

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

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

发布评论

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

评论(1

凌乱心跳 2024-12-16 17:36:44

首先,您需要为每个实体及其属性创建表(请注意,我向每个关系表添加了“id”):

  1. 例程(名称、时间戳、id)
  2. 练习 - 这对我来说看起来像是重复的,所以在这里只留下一个(muscleGroup,musclePicture,name,timeStamp,id)
  3. Session(timeStamp,id)
  4. Set(reps,timeStamp,unit,weight,id)

现在您已经有了描述每个实体的表格,您需要创建描述这些实体之间关系的表 - 与之前一样,表名大写,字段位于括号中:

  1. RoutineExercises (routine_id,exercise_id)
  2. SessionExercises (session_id,exercise_id)
  3. ExerciseSets (exercise_id, set_id) )

就是这样!现在,如果您需要将练习添加到例程中,您只需:

  1. 将一个条目添加到“练习”表中
  2. 通过将一个元组添加到“RoutineExercises”表中来建立关系,其中“routine_id”是您的例程 ID,“exercise_id”是练习中新创建的条目的 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):

  1. Routine (name, timestamp, id)
  2. Exercise - this looks like a duplicate to me, so leaving one only here (muscleGroup, musclePicture, name, timeStamp, id)
  3. Session (timeStamp, id)
  4. Set (reps, timeStamp, unit, weight, id)

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:

  1. RoutineExercises (routine_id, exercise_id)
  2. SessionExercises (session_id, exercise_id)
  3. ExerciseSets (exercise_id, set_id)

That's it! Now if you need to add an exercise to a routine, you simply:

  1. Add an entry into Exercise table
  2. Establish the relationship by adding a tuple into RoutineExercises table where routine_id is your routine ID and exercise_id is the ID of the newly created entry in the Exercise table

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.

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