当您有两种类型的记录时,该表的最佳数据库设计是什么? [英] what is the best database design for this table when you have two types of records

查看:151
本文介绍了当您有两种类型的记录时,该表的最佳数据库设计是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在追踪练习。我有一个锻炼表与




  • id

  • exercise_id (外键进入练习表)



现在,一些锻炼,如体重训练有以下字段:
weight,reps (我刚刚提升了10次@ 100磅)。



和其他练习,如运行有字段:时间,距离(我刚跑了5英里,花费了1个小时)



我应该将它们全部存储在同一个表中并且只是有一些记录填写了2个字段,其他字段为空白或应分解成多个表。



在一天结束时,我想查询一天中的所有练习(将包括两种练习),所以我必须在某处进行某些切换来区分不同类型的练习。



是这种情况的最佳数据库设计

解决方案

有几种不同的模式用于在数据库表中建模面向对象的继承。最简单的是单表继承,这在这种情况下可能会很好。



实现它主要是根据您自己的建议填写一些字段,其他字段填空。


i am tracking exercises. i have a workout table with

  • id
  • exercise_id (foreign key into exercise table)

now, some exercises like weight training would have the fields: weight, reps (i just lifted 10 times @ 100 lbs.)

and other exercises like running would have the fields: time, distance (i just ran 5 miles and it took 1 hours)

should i store these all in the same table and just have some records have 2 fields filled in and the other fields blank or should this be broken down into multiple tables.

at the end of the day, i want to query for all exercises in a day (which will include both types of exercises) so i will have to have some "switch" somewhere to differentiate the different types of exercises

what is the best database design for this situation

解决方案

There are a few different patterns for modelling object oriented inheritance in database tables. The most simple being Single table inheritance, which will probably work great in this case.

Implementing it is mostly according to your own suggestion to have some fields filled in and the others blank.

这篇关于当您有两种类型的记录时,该表的最佳数据库设计是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆