If there are any permament tables on a DB, a new dm object can be created that contains those tables, along with their primary and foreign key constraints.

Currently this only works with MSSQL and Postgres databases.

The default database schema will be used; it is currently not possible to parametrize the funcion with a specific database schema.

dm_learn_from_db(dest, ...)



A src-object on a DB or a connection to a DB.


Experimental lifecycle

Additional parameters for the schema learning query. Currently supports schema (default: "public") and table_type (default: "BASE TABLE") for Postgres databases.


A dm object with the tables from the DB and the respective key relations.

See also

Other DB interaction functions: copy_dm_to()


if (FALSE) { src_sqlite <- dplyr::src_sqlite(":memory:", create = TRUE) iris_key <- mutate(iris, key = row_number()) # setting key constraints currently doesn't work on # SQLite but this would be the code to set the PK # constraint on the DB iris_dm <- copy_dm_to( src_sqlite, dm(iris = iris_key), set_key_constraints = TRUE ) # and this would be the code to learn # the `dm` from the SQLite DB iris_dm_learned <- dm_learn_from_db(src_sqlite) }