MS-SQL Bulk Insert with RODBC

前端 未结 6 1768
南方客
南方客 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:54

    Using RODBC, the fastest insert we've been able to create (260 million row insert) looks like the following (in R pseudo code):

    ourDataFrame <- sqlQuery(OurConnection, "SELECT myDataThing1, myDataThing2
                                             FROM myData")
    ourDF <- doStuff(ourDataFrame)
    write.csv(ourDF,ourFile)  
    sqlQuery(OurConnection, "CREATE TABLE myTable ( la [La], laLa [LaLa]);
                             BULK INSERT myTable FROM 'ourFile' 
                                  WITH YOURPARAMS=yourParams;")
    

    If you're running this from between servers, you need a network drive that the R server can write to (e.g. one server with permissions for writing to the DB uses Rscript to productionalize the code), and the SQL Server can read from.

提交回复
热议问题