| dm_add_pk {dm} | R Documentation |
Add a primary key
Description
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, without altering foreign keys previously pointing to that primary key.
Usage
dm_add_pk(
dm,
table,
columns,
...,
autoincrement = FALSE,
check = FALSE,
force = FALSE
)
Arguments
Details
There can be only one primary key per table in a dm.
It's possible though to set an unlimited number of unique keys using dm_add_uk()
or adding foreign keys pointing to columns other than the primary key columns with dm_add_fk().
Value
An updated dm with an additional primary key.
See Also
Other primary key functions:
dm_add_uk(),
dm_get_all_pks(),
dm_get_all_uks(),
dm_has_pk(),
dm_rm_pk(),
dm_rm_uk(),
enum_pk_candidates()
Examples
nycflights_dm <- dm(
planes = nycflights13::planes,
airports = nycflights13::airports,
weather = nycflights13::weather
)
nycflights_dm %>%
dm_draw()
# Create primary keys:
nycflights_dm %>%
dm_add_pk(planes, tailnum) %>%
dm_add_pk(airports, faa, check = TRUE) %>%
dm_add_pk(weather, c(origin, time_hour)) %>%
dm_draw()
# Keys can be checked during creation:
try(
nycflights_dm %>%
dm_add_pk(planes, manufacturer, check = TRUE)
)
[Package dm version 1.0.10 Index]