Skip to content
Advertisement

How to design entity tables for entities with multiple names

I want to create a table structure to store customers and I am facing a challenge: for each customer I can have multiple names, one being the primary one and the others being the alternative names.

The initial take on the tables looks like this:

CREATE TABLE dbo.Customer (
CustomerId INT IDENTITY(1,1) NOT NULL --PK
 -- other fields below )


CREATE TABLE dbo.CustomerName (
CustomerNameId INT IDENTITY(1,1) NOT NULL -- PK
,CustomerId INT -- FK to Customer
,CustomerName VARCHAR(30)
,IsPrimaryName BIT)    

Though, the name of the customer is part of the Customer entity and I feel that it belongs to the Customer table. Is there a better design for this situation?

Thank you

Advertisement

Answer

Personally, I would keep the Primary name in the Customer table and create an “AlternateNames” table with a zero-to-many relationship to Customer.

This is because presumably most of the time when you are returning customer data, you are only going to be interested in returning the Primary Name. And probably the main (if not only) reason you want the alternate names is for looking up customers when an alternate name has been supplied.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement