How to setup MySQL table to follow a variable over time? -
say have several registered users in website.
users saved on single table 'users' assigns unique id each 1 of them.
i want allow users track expenses, miles driven, temperature, etc.
i can't sure each user enter value all trackable variables when login -- example of happen be:
'example data' user date amount miles temp etc 1 3/1/2010 $10.00 5 54 2 3/1/2010 $20.00 15 1 3/12/2010 5 55 1 3/15/2010 $10.00 25 51 3 3/20/2010 45 3 4/12/2010 $20.00 10 54
what best way set tables situation?
should create table exclusive each user when register? (could end thousands of user-exclusive tables)
'user-1 table' date amount miles temp etc 3/1/2010 $10.00 5 54 3/12/2010 5 55 3/15/2010 $10.00 25 51 'user-3 table' date amount miles temp etc 3/20/2010 45 4/12/2010 $20.00 10 54 , on...
should create single table same example data above? (could end gigantic table needs combed find rows requested user id's).
'user data table' user date amount miles temp etc 1 3/1/2010 $10.00 5 54 2 3/1/2010 $20.00 15 1 3/12/2010 5 55 1 3/15/2010 $10.00 25 51 3 3/20/2010 45 3 4/12/2010 $20.00 10 54
any suggestions?
databases built handle similar data set together.
what want single user-data-table, multiple users in same table split user_id. might want further normalize though, stores:
user date type units 1 3/1/2010 dollars 10.00 1 3/1/2010 miles 5 1 3/1/2010 temp 54 2 3/1/2010 dollars 20.00 2 3/1/2010 miles 15 1 3/12/2010 miles 5 1 3/12/2010 temp 55 etc
or further if user+date makes specific trip
trip-table tripid user date ========= ======== ========= 1 1 3/1/2010 type-table typeid description ========= ============ 1 dollars 2 miles etc trip-data tripid type units ========= ======== ======= 1 1 10.00 1 2 5 etc
however, if (or always) show data in form entered, data pivoted on input columns (like spreadsheet), better off sticking un-normalised form brevity, programmability , performance.
could end gigantic table needs combed find rows requested user id's
assuming employ indexes , judiciously, modern rdbms built handle gigantic amounts of data. indexes allow queries seek data needs, there little penalty in keeping in 1 table.
Comments
Post a Comment