Learn R Programming

dm (version 0.0.6.9000)

dm_rm_pk: Remove a primary key from a table in a dm object

Description

dm_rm_pk() removes a primary key from a table in the underlying data_model-object; leaves the dm object unaltered otherwise.

Foreign keys that point to the table from other tables, can be optionally removed as well.

Usage

dm_rm_pk(dm, table, rm_referencing_fks = FALSE)

Arguments

dm

A dm object.

table

A table in the dm.

rm_referencing_fks

Boolean: if FALSE (default), will throw an error if there are foreign keys addressing the primary key that is to be removed. If TRUE, the function will remove, in addition to the primary key of the table argument, also all foreign key constraints that are pointing to it.

Value

An updated dm without the indicated primary key.

See Also

Other primary key functions: dm_add_pk(), dm_get_all_pks(), dm_get_pk(), dm_has_pk(), enum_pk_candidates()

Examples

Run this code
# NOT RUN {
library(dplyr)
nycflights_dm <- dm_nycflights13()

nycflights_dm %>%
  dm_rm_pk(airports, rm_referencing_fks = TRUE) %>%
  dm_has_pk(planes)

nycflights_dm %>%
  dm_rm_pk(planes, rm_referencing_fks = TRUE) %>%
  dm_has_pk(planes)
# }

Run the code above in your browser using DataLab