dm_add_pk() marks the specified columns as the primary key of the specified table.
check == TRUE, then it will first check if
the given combination of columns is a unique key of the table.
force == TRUE, the function will replace an already
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)
A table in the
Table columns, unquoted.
dm_add_pk(): An updated
dm with an additional primary key.
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.
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`.