Store different rows type in single table

Architectureforeign keysqlite

I'd like to create a DB to store different rows type. It will be kind of event list with time stamp. So I'd like to have an Event table with relations to other tables – each table will be a row type (Transition, Position, Error):
enter image description here

Is this a good approach? Possible drawbacks:

  • as a result I'll have to take care that every row in Event exactly 1 FK not null as it can relate to exactly 1 event
  • when adding new event type I'll have to upgrade* Event
  • when I'll have many event types the result will be that a row in Event table will have mostly null columns and only 1 will be not null

EDIT: Transition, Position, Error, Location tables has unique columns which are not put in the image above, e.g. Transition has type, Position has 'latitude'/'longitude', Error has payload etc.

* By upgrade, I mean when I need to add new type to Event table I'll require rewrite whole Event table – as I'm working on Android it'll require using method SQLiteOpenHelper->onUpgrade.

Best Answer

You have it the other way round.

Put EventId and EventName on Event table and reference EventId in other tables. In other words,

  1. Add EventId column in Transition, Position and Error tables.
  2. Remove time_stamp, transition_id, position_id, and error_id from the Event table.