Because you haven't posted you schema as SQL DDL, I'm having problems seeing how these tables can work in practise. Here's my attempt:
It would seem a fair assumption that an employee must be a person, so that's easy enough (guessing data types and domain rules):
CREATE TABLE NaturalPersons
(
PersonId INTEGER NOT NULL UNIQUE
);
CREATE TABLE Employees
(
PersonId INTEGER NOT NULL UNIQUE
REFERENCES NaturalPersons (PersonId),
EmployeeID CHAR(3) NOT NULL UNIQUE
CHECK (EmployeeID LIKE '[A-Z][0-9][0-9]')
);
The table name 'PersonData' doesn't reveal much but from the data element names it seems that something is being transferred from one person/employee to another:
CREATE TABLE Transfers
(
FromPersonId INTEGER
REFERENCES NaturalPersons (PersonId),
FromEmployeeID CHAR(3)
REFERENCES Employees (EmployeeID),
ToPersonId INTEGER
REFERENCES NaturalPersons (PersonId),
ToEmployeeID CHAR(3)
REFERENCES Employees (EmployeeID)
);
Hmm, all NULL
able columns means we can't have a PRIMARY KEY
but I wonder if there's a key at all...?
We only want one type of ID for 'from' and 'to' respectively:
ALTER TABLE Transfers ADD
CONSTRAINT only_one_from_ID
CHECK (
(FromPersonId IS NULL AND FromEmployeeID IS NOT NULL)
OR
(FromPersonId IS NOT NULL AND FromEmployeeID IS NULL)
);
ALTER TABLE Transfers ADD
CONSTRAINT only_one_to_ID
CHECK (
(ToPersonId IS NULL AND ToEmployeeID IS NOT NULL)
OR
(ToPersonId IS NOT NULL AND ToEmployeeID IS NULL)
);
We will also want a 'common sense' business rules to prevent transfers from and to the same person/employee:
ALTER TABLE Transfers ADD
CONSTRAINT FromPersonId_cannot_be_ToPersonId
CHECK (FromPersonId <> ToPersonId);
ALTER TABLE Transfers ADD
CONSTRAINT FromEmployeeId_cannot_be_ToEmployeeId
CHECK (FromEmployeeId <> ToEmployeeId);
That's about the best we can do, but we have a couple of problems:
INSERT INTO NaturalPersons (PersonId) VALUES (1), (2), (3), (4);
INSERT INTO Employees (PersonId, EmployeeID) VALUES (1, 'A11'), (2, 'B22');
-- transfer to same entity - oops!:
INSERT INTO Transfers (FromPersonId, ToEmployeeID) VALUES (1, 'A11');
-- Duplicate transfer - oops!:
INSERT INTO Transfers (FromEmployeeId, ToPersonID) VALUES (1, 'B1'); -- duplicate
INSERT INTO Transfers (FromPersonId, ToEmployeeID) VALUES ('A1', 2); -- duplicate
In other words, mixing PersonId and EmployeeID in the same table makes it hard to write basic data rules.
If I am correct in assuming an employee is a person, why not just use PersonID only?
If an employee is not a person, can you post your schema (data type, constraints, etc) please?