George
George

Reputation: 73

Import dataframe from SQL Server into R

I have a working R script. Now, I extract the data from the SQL server into an Excel Sheet and import this Excel sheet into R. I would like to import directly from the SQL Server. The data I have:

Is this enough to extract the database from this SQL Server?

Upvotes: 0

Views: 8137

Answers (1)

Eray Balkanli
Eray Balkanli

Reputation: 7990

I think it is enough. You can benefit from RODBC library like below:

library(RODBC)
dbhandle <- odbcDriverConnect('driver={SQL 
Server};server=mysqlhost;database=mydbname;trusted_connection=true')
res <- sqlQuery(dbhandle, 'select * from information_schema.tables')

Ref: SQL Server RODBC Connection

EDIT: For your case, you can try:

library(RODBC)
dbhandle <- odbcDriverConnect('driver={SQL 
Server};server=mysqlhost;database=mydbname;uid=yourusername;pwd=yourpassword')
res <- sqlQuery(dbhandle, 'select * from information_schema.tables')

Ref: https://blog.learningtree.com/querying-sql-server-data-from-r-using-rodbc/

Upvotes: 3

Related Questions