Please excuse me if this is a stupid question, but I'm new at relational databases and can't seem to find the answer (probably because everyone else already knows the answer).
I'm storing test data that may include times in various formats that are slightly different (TAI, UTC, GPS, etc). I'm not sure I want to force the times to be converted to an arbitrary consistent format before being input (or maybe that's the best way?), but assuming I can keep the flexibility, I plan to use a reference table (lookup table) of time types like so:
ref_time_types
--------------
id (PK)
desc (UTC, GPS, TAI, etc)
and I'll also have a table to store the actual times:
tbl_time
-------------
id (PK)
ref_time_types.id (FK)
seconds
year
.
.
.
My question is I'm sure very basic. Should I establish a bidirectional relationship between these, or a unidirectional many-to-one from tbl_time to ref_time_types? I can't think of any reason I would want to find all the UTC times, for example. Is that the guiding principle on whether to create a bidirectional relationship? Is there any best practice when it comes to relationships for reference tables?
I'm using python, sqlalchemy, and sqlite if that makes any difference.
Do you actually need to preserve the format?
ref_time_types
altogether. Also, do use date/time type supported by your DBMS - I don't see a particular reason to split various date/time components to separate fields unless you actually want to query on these individual components (and want to index them).
Should I establish a bidirectional relationship between these, or a unidirectional many-to-one from tbl_time to ref_time_types?
As discussed above, you won't need any relationship in the first case (since there is only one table). A relationship would be many-to-1 the second case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.