I am in the process of changing a database schema (SQL Server) to use synthetic keys without changing the business logic in the database (Foreign key relationships)
As I have understood it, a foreign key in one table should be able to reference a candidate (non primary) key in another table as long as the target key is UNIQUE/NOT NULL. But I cannot find a way to model this in EA.. It just gives me an error saying "All primary key columns must be selected!" Am I doing something wrong?
I can append the database with this kind of relationships manually (eg SQL Server accepts it), but would rather have it drawn in the EA database diagram. (So that I could just generate the DDL later)
Below is given an example of what I want to model
CREATE TABLE ENTITYSCHEMA (
ID bigint identity(1,1) NOT NULL,
NAME nvarchar(50) NOT NULL,
CLASSID bigint NOT NULL
);
ALTER TABLE ENTITYSCHEMA ADD CONSTRAINT PK_ENTITYSCHEMA
PRIMARY KEY CLUSTERED (ID)
;
ALTER TABLE ENTITYSCHEMA
ADD CONSTRAINT UQ_ENTITYSCHEMA_CLASSID UNIQUE (ID, CLASSID)
;
CREATE TABLE SCHEMAPROPERTY (
ID bigint identity(1,1) NOT NULL,
SCHEMAID bigint NOT NULL,
PROPERTYID bigint NOT NULL,
CLASSID bigint NOT NULL
}
ALTER TABLE SCHEMAPROPERTY ADD CONSTRAINT PK_SCHEMAPROPERTY
PRIMARY KEY CLUSTERED (ID)
;
ALTER TABLE SCHEMAPROPERTY ADD CONSTRAINT FK_SCHEMAPROPERTY_ENTITYSCHEMA
FOREIGN KEY (SCHEMAID, CLASSID) REFERENCES ENTITYSCHEMA (ID, CLASSID)
;