dm_add_pk()
marks the specified columns as the primary key of the specified table.
If check == TRUE
, then it will first check if
the given combination of columns is a unique key of the table.
If force == TRUE
, the function will replace an already
set key.
dm_rm_pk()
removes a primary key from a table and leaves the dm
object otherwise unaltered.
Foreign keys that point to the table from other tables, can be optionally removed as well.
dm_add_pk(dm, table, columns, check = FALSE, force = FALSE) dm_rm_pk(dm, table, rm_referencing_fks = FALSE)
dm | A |
---|---|
table | A table in the |
columns | Table columns, unquoted. |
check | Boolean, if |
force | Boolean, if |
rm_referencing_fks | Boolean: if |
For dm_add_pk()
: An updated dm
with an additional primary key.
For dm_rm_pk()
: An updated dm
without the indicated primary key.
Currently, keys consisting of more than one column are not supported. This feature is planned for dm 0.2.0. The syntax of these functions will be extended but will remain compatible with current semantics.
Other primary key functions:
dm_get_all_pks()
,
dm_get_pk()
,
dm_has_pk()
,
enum_pk_candidates()
nycflights_dm <- dm( planes = nycflights13::planes, airports = nycflights13::airports ) nycflights_dm %>% dm_draw()# the following works nycflights_dm %>% dm_add_pk(planes, tailnum) %>% dm_add_pk(airports, faa, check = TRUE) %>% dm_draw()# the following throws an error: try( nycflights_dm %>% dm_add_pk(planes, manufacturer, check = TRUE) )#> Error : (`manufacturer`) not a unique key of `planes`.