Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Basic Synthetic Key Question - QV

Hello Qlik Wizards!

Quick (and hopefully easy) Synthetic Key question. Here's my issue:

I have three tables [Applicant], [Applicant Child], and [Gender]. Applicant and Applicant Child are both normal entities while Gender is essentially a reference table. Both Applicant and Applicant Child have the field "Applicant ID" in them for relating to one another, but they also both have "Gender ID" so we're able to determine the Gender of both Applicants and their children. This creates a synthetic key with Applicant ID and Gender ID.

Is there a way to remove this Synthetic Key? Should I?

Thanks!

15 Replies
Miguel_Angel_Baeyens

Synthetic keys are not that wrong if they happen on purpose and can be kept safely on the model without any significant impact on performance. There is no need for a composite key which basically requires a maintenance that otherwise QlikView does automatically.

However, if the fields are named alike but the values do not correspond (for example, Gender is Male/Female in one case and M/F in the other, and ID contains customer ID in one case and gender ID in another) the resulting synthetic table would be a cartesian product of all possible values, due to a poorly designed data model which is what it causes performance issues and problems with selections.

Abounding on the concept: Synthetic Keys

Anonymous
Not applicable
Author

See above for data model.

If I alias both GenderID fields, won't it break connection to the third table that holds the reference value? Or, how would I point the GenderID FK to the third table to get the corresponding "M" or "F"

Anonymous
Not applicable
Author

Thanks for the response.

Totally agree. I don't inherently have an issues with a Synthetic Key, but I'm not always sure when I should spend time trying to get rid of them.

I don't want to use a Composite key here because the Applicant ID the the PK across a dozen or more tables in the model.

Thanks for the thoughts.

buzzy996
Master II
Master II

i think u leave it the gender table this case.

do u think there is a advantage to create another table like gender in this model?

avinashelite

try this script

//-----ApplicantChild Table-----

ApplicantChild:

Load

"APPLICANTID"&'_'&GENDERID as Key,

  "ID" as [Applicant Child ID],

  "APPLICANTID" as [Applicant ID ApplicantChild],

  "GENDERID" as [Gender ID ApplicantChild]

Resident [OSUSR_H0L_APPLICA4];

//-----Applicant Table-----

Applicant:

Load

"ID"&'_'&GENDERID as Key,

  "ID" as [Applicant ID ApplicantChild],

   "GENDERID" as [Gender ID Applicant]

Resident [OSUSR_H0L_APPLICAN];

Master_Link:

LOAD Key,

[Gender ID ApplicantChild] as [Gender ID]

resident

ApplicantChild;


LOAD Key,

[Gender ID Applicant] as [Gender ID]

resident

Applicant;

//-----Gender Table-----

Gender:

Load

  "ID" as [Gender ID],

  "CODEVALUE" as [Gender Code Value],

  "DESCRIPTION" as [Gender Description],

  "SORTORDER" as [Gender Sort Order],

  "ACTIVEFLAG" as [Gender Active Flag]

Resident [OSUSR_VL2_GENDER];

adamdavi3s
Master
Master

A quick link table might just help clean up the data model, I would personally choose to do this because I like the model to be synthetic key free for my own sanity! Might be overkill though

//-----ApplicantChild Table-----

ApplicantChild:

Load rowno() as %ACKEY

  "ID" as [Applicant Child ID],

  "APPLICANTID" as [Child Applicant ID],

  "GENDERID" as [Child Gender ID]

Resident [OSUSR_H0L_APPLICA4];

//-----Applicant Table-----

Applicant:

Load as %APKEY

  "ID" as [Applicant Applicant ID],

   "GENDERID" as [Applicant Gender ID]

Resident [OSUSR_H0L_APPLICAN];

//-----LinkTable-----

Link:

LOAD %ACKEY, [Child Applicant ID] as [Applicant ID], [Child Gender ID] as [Gender ID]

Resident ApplicantChild;

concatenate

LOAD %APKEY, [Applicant Applicant ID] as [Applicant ID], [Applicant Gender ID] as [Gender ID]

Resident Applicant;

DROP FIELDS [Child Applicant ID], [Applicant Applicant ID] , [Child Gender ID] , [Applicant Gender ID]

//-----Gender Table-----

Gender:

Load

  "ID" as [Gender ID],

  "CODEVALUE" as [Gender Code Value],

  "DESCRIPTION" as [Gender Description],

  "SORTORDER" as [Gender Sort Order],

  "ACTIVEFLAG" as [Gender Active Flag]

Resident [OSUSR_VL2_GENDER];