mdb_schema: Generate Schema DDL or Column Types

View source: R/advanced.R

mdb_schemaR Documentation

Generate Schema DDL or Column Types

Description

mdb-schema is a utility program distributed with MDB Tools. It produces DDL (data definition language) output for the given database, which can be passed to another database to recreate the Access table structure. With mode = "legacy" (the default), it returns a readr col spec for the table instead.

Usage

mdb_schema(
  path,
  table = NULL,
  mode = c("legacy", "ddl"),
  condense = FALSE,
  namespace = NULL,
  backend = c("access", "sybase", "oracle", "postgres", "mysql", "sqlite"),
  drop_table = FALSE,
  not_null = TRUE,
  default_values = FALSE,
  not_empty = FALSE,
  comments = TRUE,
  indexes = TRUE,
  relations = TRUE,
  as_list = TRUE
)

Arguments

path

Path to .mdb/.accdb file.

table

Table name(s). For mode = "ddl", defaults to all user tables. For mode = "legacy", exactly one table name must be given.

mode

"legacy" (default) returns a readr::cols() specification, matching the k5cents/mdbr canonical API. Requires the readr package. "ddl" returns DDL text.

condense

Logical; only used when mode = "legacy". When TRUE, passes the col spec through readr::cols_condense(). Default FALSE.

namespace

Prefix identifiers with namespace, equivalent to -N/--namespace. Only used when mode = "ddl".

backend

Target DDL dialect. Supported values are access, sybase, oracle, postgres, mysql, and sqlite. Only used when mode = "ddl".

drop_table

Issue ⁠DROP TABLE⁠ statements.

not_null

Include ⁠NOT NULL⁠ constraints.

default_values

Include DEFAULT values.

not_empty

Include ⁠CHECK <> ''⁠ constraints.

comments

Include ⁠COMMENT ON⁠ statements.

indexes

Export indexes.

relations

Request foreign key constraints. Current library-mode implementation emits a placeholder comment; full FK export is not yet implemented.

as_list

Logical; defaults to TRUE. When TRUE, returns a named mdblist of DDL text entries keyed by table name. Only used when mode = "ddl".

Value

When mode = "legacy", a readr::cols() specification (optionally condensed via readr::cols_condense()). Requires the readr package. When mode = "ddl" and as_list = TRUE, a named mdblist of table-level DDL text.

Examples

db <- mdbr:::.mdb_example_nwind_path()
if (nzchar(db)) {
  mdb_schema(db, table = "Products")
  mdb_schema(db, table = "Products", mode = "ddl")
}

mdbr documentation built on May 28, 2026, 5:09 p.m.