Determine which columns would be good candidates to be used as foreign keys of a table,
and reference the primary key column of another dm object's table.
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 of use 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, and which columns would not be suitable.
cdm_enum_fk_candidates() first checks if ref_table has a primary key set.
Then, for each column of table, a join operation will be tried, with argument by matching
the respective column with the primary key of ref_table.
This tests implicitly for
type compatibility (on most sources).
Based on the result of the join, the
entry in the result column why is:
an empty entry, if the column is a candidate
the total percentage and individual numbers of missing matches between the entries of the
respective column in table table and the primary column entries in table ref_table.
the error message triggered by the error (often stating the mismatched column types)
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