Determine which columns would be good candidates to be used as foreign keys of a table,
to reference the primary key column of another table of the dm
object.
cdm_enum_fk_candidates(dm, table, ref_table)enum_fk_candidates(zoomed_dm, ref_table)
A dm
object.
The table whose columns should be tested for suitability as foreign keys.
A table with a primary key.
A dm
with a zoomed table.
A table that lists which columns of table
would be suitable candidates for
foreign key columns to reference ref_table
, which columns would not be suitable,
and the reason why
.
cdm_enum_fk_candidates()
first checks if ref_table
has a primary key set,
if not, an error is thrown.
If ref_table
does have a primary key, then a join operation will be tried using
that key as the by
argument of join() to match it to each column of table
.
Attempting to join incompatible columns triggers an error.
The outcome of the join operation determines the value of the why
column in the result:
an empty value for a column of table
that is a suitable foreign key candidate
the count and percentage of missing matches for a column that is not suitable
the error message triggered for unsuitable candidates that may include the types of mismatched columns
enum_fk_candidates()
works like cdm_enum_fk_candidates()
with the zoomed table as table
.
Other foreign key functions:
cdm_add_fk()
,
cdm_get_all_fks()
,
cdm_get_fk()
,
cdm_has_fk()
,
cdm_rm_fk()
# NOT RUN {
cdm_enum_fk_candidates(cdm_nycflights13(), flights, airports)
# }
Run the code above in your browser using DataLab