Member-only story

How to Import Data into MS SQL Server via R? (Part 1: csv, Excel, Snowflake)

DigNo Ape
3 min readFeb 8, 2023

--

Manipulating the data resides in multiple platforms plays fundamental role when you do the data analysis, machine learning, reporting, etc. We are going to discuss multiple approaches of leveraging R to upload the data in csv file, MS Excel, Snowflake into MS SQL Server.

csv into MS SQL Server

  • Required package: RODBC
  • Steps:

Step 0: Set up MS SQL server in ODBC Data Source Admin.

Step 1: Define SQL Server connection.

Step 2: Set working directory and Read the csv file as a data frame df.

Step 3: Import the df into target_laptop_price_csv via sqlSave function.

Step 4: Close the connection.

library(RODBC)
setwd('H:/Tutorial')
conn <- odbcDriverConnect('driver={SQL Server};server=Your Server;database=Your DB;trusted_connection=true')
df <- read.csv("target_laptop_price.csv")
sqlSave(conn, df, tablename="target_laptop_price_csv", rownames=FALSE)
odbcClose(conn)

MS Excel into MS SQL Server

  • Required packages: RODBC/readxl
  • Steps:

Step 0: Set up MS SQL server in ODBC Data Source Admin.

--

--

DigNo Ape
DigNo Ape

Written by DigNo Ape

我們秉持著從原人進化的精神,不斷追求智慧的累積和工具的運用來提升生產力。我們相信,每一個成員都擁有無限的潛力,透過學習和實踐,不斷成長和進步。

No responses yet