Composite Foreign key with a calculated column
AbeAxiomatic
Posts: 5 New member
I have 2 tables - 1 is a superset of the other. The child has a calculated column on the second half of the composite shared key.
- dbo.Entity is the parent table with a Primary Key on (EntityId, EntityTypeId). EntityTypeId is an FK to ref.EntityType
- entity.Person represents the subset, has a Primary Key on EntityId, a persisted calculated column EntityTypeId = 10 (Corresponds to ref.EntityType record for 'Person'), and a Foreign Key Constraint (EntityId, EntityTypeId) to dbo.Entity.
Tagged:
Answers
Unfortunately, SQL Data Generator doesn't handle composite primary keys as it will not generate data for a unique index where it sees the possibility that a duplicate can be generated. It will only allow generation if one of the two columns is set to unique.
This is listed internally as SDG-921 and I have put a reference against your post here in that issue.
I will update here when I have further information!
Kind regards,
Alex
Have you visited our Help Center?
We're still not quite sure what's going wrong here, it does seem like we're doing something wrong with the composite foreign key.
We've managed to work around it by using a SQL Statement generator on entity.Person.EntityId that connects to the same database with the query
<pre class="CodeBlock"><code>SELECT EntityId FROM dbo.Entity WHERE EntityTypeId = 10
This ensures that the foreign key is respected.I'll update here further when I have any more information on the original generator having an issue.
Kind regards,
Alex
Have you visited our Help Center?
The development team have reviewed issue SDG-921 as part of a periodical review and prioritization of open issues and, unfortunately, they are unable to fix it at this time.
When reviewing bugs the development team take into account the impact it has and the number of users affected and unfortunately we are unable to fix all bugs and have to prioritize fixing the ones that cause the greatest impact.
Thank you for your understanding.
Kind regards,
Alex
Have you visited our Help Center?