I have three tables: Customers, Providers and Locations. I need to create a fourth table called Contacts.
I'd like to have any number of Contacts associated with any row in the Customers, Providers and Locations table so I ended up with something like this.
CREATE TABLE [dbo].[Contacts] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[CustomerId] INT NULL,
[ProviderId] INT NULL,
[LocationId] INT NULL,
[Name] NVARCHAR (80) NULL,
[Email] NVARCHAR (80) NULL,
[Phone] NVARCHAR (80) NULL,
[Title] NVARCHAR (80) NULL,
[Address] NVARCHAR (120) NULL,
);
I don't find this very elegant. In addition to having unused columns, I probably should add a constraint to ensure exactly one of CustomerId, ProviderId and LocationId are not NULL.
Another alternative is to create a many-to-many join table. This won't need any unused columns. But it still seems like a waste as no contact will ever related to more than one company.
Is anyone aware of any slicker solutions?