Skip to content Skip to sidebar Skip to footer

Import Data From Sql Server To R

I'm trying to import data from SQL Server to R. I was given the server name, user name and password to the SQL Server database. I've installed RODBC in R. But I don't know how to w

Solution 1:

This is a typical SQL Server connection using DBI+odbc packages :

library(DBI)
library(odbc)

conn <- DBI::dbConnect(
    odbc::odbc(),
    Driver = "SQL Server",
    Server = "ServerName",
    Database = "DatabaseName",
    uid = "UserName",
    pwd = "Password",
    options(connectionObserver = NULL)
  )

data <- dbGetQuery(conn, "SELECT * FROM ...")

DBI is recommended by R Studio, and faster than RODBC. Credits @r2evans for checking this.

Post a Comment for "Import Data From Sql Server To R"