Quick question about the most efficient was to handle this, I have a database which has a tree structure of user types,
system --- 1 to m --- account --- 1 to m --- customer
All three types can have multiple email addresses, I was wondering what would be the best way to handle this in a database, all user types have auto_id as their primary key so having a table with address identified by there related primary key wont work as there will be potentially 3 of each. e.g. email with key 2 , will link to system with id 2 , account with id 2 , etc.
Should I create a table of email addresses for each type .? Or is there a more elegant solution .?
Thanks
You either have an email table that has a foreign key which is either a system_id, account_id, or customer_id. Then you can have a field specifying the type of that foreign key. Another more complicated strategy would be to have still the email table but no foreign key. Another table which you would call email_relation consisting of the email_id and the foreign key. That way you could use one e-mail address for all three tables.
Example of the use of two tables
if you want the customer table including the e-mail address
If you want all e-mail to a system you could also