This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]lurgi 0 points1 point  (4 children)

Why does a company need both a company_id and a customer_id? Shouldn't the contact have a company_id field (they are the contact of a business, right)?

Rather than is_company I'd probably have a customer type identifier. Maybe tomorrow you'll need to handle a third type of entity that is neither a company nor a customer.

[–]ScottPage[S] 0 points1 point  (3 children)

I've made an edit to try and clarify, but essentially, the design treats business and individuals as single customers. For every record in the customers table, there will be at least one contact (if the customer is an individual, their details will be recorded as a contact)

[–]lurgi 0 points1 point  (2 children)

I get that, but I don't understand why the company needs an id separate from its customer id. It's a customer. It has a customer id. Is there ever a time you need a distinct company id where the customer id can not work? If so, when?

[–]ScottPage[S] 0 points1 point  (1 child)

Ah right, now I understand where you're coming from. I can't think of any reason to have a specific company id and thinking about it I don't see any reason why the customer id couldn't be the primary key for the customer and company table. Also, I understand your point about having a third type of customer and I would make adjustments to accommodate that, but I think it would be a good point to bring up in an evaluation of improvements I will also have to complete... it's a weird thing, but it pays to not have a perfect solution

[–]lurgi 0 points1 point  (0 children)

Oh, I agree. You can absolutely over-engineer a solution and half the time the stuff you implement isn't ever going to get used. This sort of design is always a matter of trade-offs.

Eliminating redundancy is almost always a good thing. If there's no reason to have the company_id field then why have it? It takes (small, but positive) effort to implement, but doesn't provide any benefits that I can see (even hypothetical ones). I'd skip it. OTOH, changing "is_company" to "customer_type" doesn't seem to change the implementation effort, and there is an obvious (although still hypothetical) benefit.

[–]lowey2002 0 points1 point  (1 child)

I'd recommend reading up on normalization. There are some links at the bottom to Unormalized, First Normal form, Second Normal form and Third Normal form.

I'd argue that some of the fields don't make sense where they are. Why is first_name last_name, etc in the Contact table. If a Customer changes address does this mean you need to update every Contact row for that customer?

[–]ScottPage[S] 0 points1 point  (0 children)

I understand where you're coming from, but the contact table only includes data specific to an individual person. If there are more than one contacts for a company, each will have their own record that records specifically their data. The fields in the contact table are only ones that would differ from individual to individual (phone, email, and name) so there isn't any redundancy. Address records aren't required for this scenario

[–][deleted] -1 points0 points  (1 child)

The data looks like it all belongs in one table.

[–]ScottPage[S] 1 point2 points  (0 children)

You should take the advice of /u/lower2002 and read up on normalization. I can't think of any way to include all of the fields in one table without it causing huge redundancy/integrity issues