Question

This is academic so please, no comments that in real world it is not done like that :)

The point of this exercise was to normalize as much as possible.

The point is: An Employee can have 1 role (but 1 role can be assigned to more employees). A role can be either Reg.Employee or Lead, again these can be assigned to more roles (not repeating values) That is the problem as the Role would hold two FKs (one to Reg.Employee and the other one to Lead) but both would need to be nullable, righ? If I make one nullable, when creating a record for the other one, I would need to assign this role as well. So I assume in the ERD abstraction, the only way would be to make both FKs nullable. enter image description here

Was it helpful?

Solution

Not sure I understand your question, so here's my statement of the problem: A Role can be none, one, or both of two 'types'.

If that's so, then yes they should both be nullable. If the role has to have at least one assigned (both cannot be null), then depending on the DBMS you may be able to express that as a constraint on the table.

Hope that helps.

Added: As it's an either/or and not both, but must be one, I don't know how to show that on an ERD. In SQL Server I would use a Check Constraint, like:

ALTER TABLE [config].[Generator]  WITH CHECK ADD  CONSTRAINT [CK_Generator] CHECK  
(( ([PNWriterProviderId] IS NOT NULL OR [BodWriterProviderId] IS NOT NULL)
and
([PNWriterProviderId] IS NULL OR [BodWriterProviderId] IS NULL)))
GO

(An example from a table I have.) Here one must not be null, and one must be null.

How to put that on an ERD diagram, as I say, I don't know.

Cheers -

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top