简体   繁体   中英

How to handle database design with time stamps and features?

I'm designing a database in MySQL, and have a couple of questions about how tables and columns ought to be defined.

Right now, I have one entity (let's call it Entity1) that will have several (5-10) features that may change with time. I will also need to be able to add features as time progresses. There are 2 designs I'm considering:

1: 1 table with Entity1 info, 1 table with a timestamp and then all of the features at that given timestamp in every row. This will make it easier to enforce the connections between all of the features.

2: 1 table with Entity1 info, and 1 table for each feature, with each having a timestamp of the addition of that row. This will reduce the amount of redundant data I store in my database.

Are either of these designs ideal? Is there some database literature I should look at? I'm a total noob with database design.

Thanks

Consider creating 2 tables: entity table and feature table.

entity (id, ...)

feature(id, entity_id_foreign_key, feature_name, created_timestamp, feature_value)

It will work if feature values are all equal type. Good thing is that you don't ever need to touch the schema if you want to add or remove features, so no migrations.

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