Scenario:
I want to create a set of users with different types and have another table to handle non-standard information for the different user types. So every user would have global attributes, like first name, last name, etc. Then specialized users might have attributes that differ from the generic information / global information.
So what I was thinking is create a table in mysql as normal with a primary key being an integer (int) and then having a secondary table that would contain all other extra fields with a primary key that always stayed the same as the primary key of the main user table. For instance: 1.1, 1.2, 1.3. Then the secondary table would have a maybe title and value.
I am not totally sure how I would do this or what would be the best way, but I am looking for the most efficient way for the computer itself and speed wise. I’m pretty much trying to just make an easy relation from one table to the next by matching id’s however there may be multiple extra fields related to a specific user.
So I may have a user with an id of 1 and he may have extra fields 1.1, 1.2 and 1.3 and it would be nice instead of having to search the entire table to just go to that specific number and then quit searching once the records had been found.
If this is confusing and not well explained please let me know.
Thanks in advance!
This is exactly what indexes are for. What you are describing is a foreign key index. they are easy to set up and extremely efficient.
See here for more info:
http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html