简体   繁体   中英

Database: When to use a JSON vs Relationship

I am building an online logbook. The most important data (aside from timestamps, aircraft, and route information) is time. The data that will be accessed most often is the total time. For that reason, I have a total_time column.

Some of the data I wish to store is the Out ( from the gate ), Off ( the ground ), On ( the ground ), and In ( to the gate ). This data will be displayed on the show view, but is not required for logic past the initial data entry.

Would it be better to store this information as JSON in a column ( {"out":1200,"off":1215,"on":1345,"in":1400} ), or in a separate table with a belongsTo (the flight entry)?

Thank you for your help and insight!

I'm not sure I entirely understand your question, but SQL could capture what you want, and make sure it's regular, too.

create table log ( 
       WHEN datetime not NULL primary key, 
       EVENT char not NULL 
         check (EVENT in ('OUT', 'OFF', 'ON', 'IN')) );

This ensures every entry has a unique key and all events are consistently recorded.

Potentially you'd want another column to indicate the "flight number" or something. That would simplify computations such as average duration.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM