How to export data from R directly to sql server?

Asked

Viewed 663 times

5

Friends, I consumed a web service with R and now I need to export this data directly to sql server. How do I?

  • Have you looked at this package? https://cran.r-project.org/web/packages/RSQLServer/index.html

  • @Clecionepunuceno: Which version of SQL Server?

  • @Josédiz , I use SQL server 2014

  • @Clecionepunuceno how so export? Vc want to popular tables in a SQL Server database using these data consumed?

1 answer

1

One of the ways you can do this is by using the RODBC package.

library(RODBC)
# Use a função odbcDriverConnect para criar uma conexão com o banco
dbhandle=odbcDriverConnect("driver={SQL Server};
                       server='your_servername';
                       database='your_database';
                       uid='your_user';
                       pwd='your_password'")

# Use a função sqlSave para salvar um data.frame em uma tabela especifica na 
# conexão criada.

sqlSave(dbhandle,'your_data_frame','you_table_name')

# Se você ainda quiser realizar a leitura de dados das tabelas disponíveis 
# no banco, use a função sqlQuery para executar uma Query.

df=sqlQuery(dbhandle,paste("SELECT * from 'your_table'"))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.