Hi all,
I'd like to read your suggestions about how to properly reference data of very diverse nature in a table.
I have a main table which relates 1-1 with some specific info. The problem is that this info varies greatly from record to record, altough there are a bunch of predefined types.
I thought about two apprroaches and I'd like to hear your opinion.
Solution #1
Add to Main table two fields : type (numeric o text) and vdata (BLOB).
Use type to identify the kind of data stored in vdata (in the form of a Map object?).
It will go like this:
Main
ID - autoinc....
blahblah - fields already in Main
type - int (e.g. 15)
vdata - BLOB (a map related to type 15 above)
So reading record "X" I will know that its vdata is of type=15 (e.g. personal data) and work on the Map object read from vdata accordingly. For a different record I could read type=7 (e.g. train data) and again I could treat the Map object as related to trains instead of to humans.
Solution #2
Add to Main table two fields: fk_type_id and fk_data_id
fk_type_id will point to a record in a "lookup table", App_type, where I store the definition of every possible type managed by my sw, along with the table name associated to it.
fk_data_id will point to a single record in the dedicated table whose name is referenced through fk_type_id above.
Something like:
App_type
ID - autoinc..
name - varchar (e.g. human, train, room.., or even 15, 7, 8 as in Solution #1)
table_name - varchar (e.g. HumanData, TrainData..)
Then for each type I define a specific table. As an example:
HumanData
ID - autoinc
name - varchar
surname - varchar
phone_number - ..
RoomData
ID -autoinc
floor -
number -
....
Either solution seems to fit. Solution2 sounds more flexible, while Solution1 appears easier.
What would you suggest? Solution3 maybe? TIA
Update: I should add that searching on the "specific" data won't be a requirement
udg
I'd like to read your suggestions about how to properly reference data of very diverse nature in a table.
I have a main table which relates 1-1 with some specific info. The problem is that this info varies greatly from record to record, altough there are a bunch of predefined types.
I thought about two apprroaches and I'd like to hear your opinion.
Solution #1
Add to Main table two fields : type (numeric o text) and vdata (BLOB).
Use type to identify the kind of data stored in vdata (in the form of a Map object?).
It will go like this:
Main
ID - autoinc....
blahblah - fields already in Main
type - int (e.g. 15)
vdata - BLOB (a map related to type 15 above)
So reading record "X" I will know that its vdata is of type=15 (e.g. personal data) and work on the Map object read from vdata accordingly. For a different record I could read type=7 (e.g. train data) and again I could treat the Map object as related to trains instead of to humans.
Solution #2
Add to Main table two fields: fk_type_id and fk_data_id
fk_type_id will point to a record in a "lookup table", App_type, where I store the definition of every possible type managed by my sw, along with the table name associated to it.
fk_data_id will point to a single record in the dedicated table whose name is referenced through fk_type_id above.
Something like:
App_type
ID - autoinc..
name - varchar (e.g. human, train, room.., or even 15, 7, 8 as in Solution #1)
table_name - varchar (e.g. HumanData, TrainData..)
Then for each type I define a specific table. As an example:
HumanData
ID - autoinc
name - varchar
surname - varchar
phone_number - ..
RoomData
ID -autoinc
floor -
number -
....
Either solution seems to fit. Solution2 sounds more flexible, while Solution1 appears easier.
What would you suggest? Solution3 maybe? TIA
Update: I should add that searching on the "specific" data won't be a requirement
udg
Last edited: