MS-SQL Bulk Insert with RODBC

前端 未结 6 1774
南方客
南方客 2020-12-18 03:10

Is it possible to perform a bulk insert into an MS-SQL Server (2000, 2005, 2008) using the RODBC package?

I know that I can do this using freebcp, but I\'m curious i

6条回答
  •  一向
    一向 (楼主)
    2020-12-18 03:43

    Now You can use dbBulkCopy from the new rsqlserver package:

    A typical scenario:

    1. You create a matrix
    2. you save it as a csv file
    3. You call dbBulkCopy to read fil and insert it using internally bcp tool of MS Sql server.

    This assume that your table is already created in the data base:

    dat <- matrix(round(rnorm(nrow*ncol),nrow,ncol)
    id.file = "temp_file.csv"                      
    write.csv(dat,file=id.file,row.names=FALSE)
    dbBulkCopy(conn,'NEW_BP_TABLE',value=id.file)
    

提交回复
热议问题