简体   繁体   中英

How should i create a database table where i will keep multiple event names and their timestamps with device token as foreign key

i'm trying to create a database but i just can't imagine it.

in one of my tables, i will keep multiple events and their timestamps and a key to know who were the person did that event.

for example;

device_token  |  login_screen |  login_screen_timestamp | button_clicked | button_clicked_timestamp | new_event | new _event_timestamp

is this how should i continue, because i can't think of any better way.But somehow i think that there should be a better way.

Without knowing what kind of data exists in each field, it will be hard to give you approval but ultimately you want to normalize your tables to reduce any type of field duplication. By following the principles of Database Normalization , you can set up your data to be algebraically stored in the most efficient manner possible while simultaneously greatly reducing the possibility of data error.

Read up on normal forms to familiarize yourself with these concept and try and shoot for 3rd Normal Form in your database (which will eliminate functional and transitive dependencies). Any additional normalization beyond 3NF can actually slow your performance so 3rd normal form should be your goal in any business setting.

A summarized list of steps to take to normalize data from non-normalized to 3rd Normal Form is as follows:

  1. List your data in tabular form with no fields null (achieving 1st Normal Form) and identify a primary key
  2. Eliminate any functional dependencies (achieving 2nd Normal Form). This just means that if you have fields that are not fully dependent on the primary key but rather one part of the composite primary key , then they need to be split into a separate table.
  3. Finally remove any transitive dependencies (achieving 3rd Normal Form). This moves any fields which depend on a non-primary key into a separate table.

So what you should see is one large table, then split into other smaller tables until the large table is 3rd Normal Form. Then you repeat the process on any newly created smaller tables until everything in your database is 3rd normal form.

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