load_df_bcp_f: Load an R Data.Frame to SQL Server Using BCP (Bulk Copy...

View source: R/load_df_bcp.R

load_df_bcp_fR Documentation

Load an R Data.Frame to SQL Server Using BCP (Bulk Copy Program)

Description

This function loads data from an R data.frame into a SQL Server database table by saving the data.frame to an temporary file and then using the BCP (Bulk Copy Program) utility.

Usage

load_df_bcp_f(
  dataset,
  server,
  db_name,
  schema_name,
  table_name,
  user = NULL,
  pass = NULL
)

Arguments

dataset

A data.frame or data.table to be loaded, or a character string specifying the filepath of a text file to be loaded.

server

The name of the SQL Server instance.

db_name

The name of the target database.

schema_name

The name of the schema containing the target table.

table_name

The name of the target table.

user

Optional. The username for SQL Server authentication.

pass

Optional. The password for SQL Server authentication.

Details

This function uses the BCP utility to efficiently load data into a SQL Server table. It supports both Windows authentication and SQL Server authentication. If a data.frame or data.table is provided, it is first written to a temporary file before being loaded.

Plans for future improvement ...

Value

A character vector containing the output of the BCP command.

Author(s)

Jeremy Whitehurst, 2025-02-05

Examples

 ## Not run: 
  # Load data from a data.frame
  df <- data.frame(id = 1:5, name = c("Alice", "Bob", "Charlie", "David", "Eve"))
  load_df_bcp_f(df, "SQLSERVER01", "MyDatabase", "MySchema", "MyTable")
  
  # Load data using SQL Server authentication
  load_df_bcp_f(df, "SQLSERVER01", "MyDatabase", "dbo", "MyTable", 
            user = "myuser", pass = "mypassword")
 
## End(Not run)


PHSKC-APDE/apde documentation built on April 14, 2025, 10:46 a.m.