Alex SUN Alex SUN -4 years ago 72
MySQL Question

Mysql table design : table roles

I have a table called enterprise in my database. If the enterprise expresses its demand to my company, the enterprise will become our prospection. And after, if the enterprise accept my company's proposal, we will sign the contract, and enterprise becomes out client.

Now, I have created 3 tables which are enterprise, prospection, client.

So, how should I design the database?

Answer Source

One approach would be to have a table Companies, and the three tables you already have. All three tables have field CompanyId that has a foreign key constratint linkining it to the companies table. This design has the advantage that you have to keep the company information in one place and there is no duplication.

Another way would be to have a field in the companies table, that marks them as an enterprise, prospect, or client.

Which design you should choose largely depends on information for the different classes. If you thinking along inheritance (i.e. a client is a prospect is a enterprise) than the company table suffices. However, if ther is a large amount of information and the information is different for each of the three classes than the first approach would be better.

You should, however, always try to keep the information in one place, i.e. in one field/table (= fully normalized). In some cases you can deviate from this principle for performance reasons, but keep in mind that this also means a higher maintenance overhead - you have to update n tables when a value changes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download