简体   繁体   English

将巨大的.Rdata文件(R数据帧)加载到SQL Server的最快方法是什么?

[英]What is the fastest way to load huge .Rdata files (R dataframes) into SQL Server?

I am currently using library(RODBC) via: 我目前正在通过以下方式使用库(RODBC):

dbhandle <- odbcDriverConnect('driver={SQL Server};server=xxxxxx;database=yyyy;trusted_connection=true')
sqlSave(dbhandle, R_table ,tablename = "SQL_table" )

The problem with this one is, it takes about 5 hours to load 10 Million rows into SQL Server. 这个问题是,将1000万行加载到SQL Server中大约需要5个小时。

Also it breaks while loading sometimes. 有时在加载时也会断裂。 So, I break the .Rdata into smaller chunks and sequentially load it into SQL Server. 因此,我将.Rdata分成较小的块,然后依次将其加载到SQL Server中。

Is there any quicker way to achieve this ? 有没有更快的方法来实现这一目标?

I would export my data in CSV format and use BULK INSERT . 我将以CSV格式导出数据并使用BULK INSERT If you really want (or have) to use sqlSave, then, the only options that come to my mind are: 如果您真的想(或必须)使用sqlSave,那么我想到的唯一选项是:

  1. be sure to set fast=TRUE in sqlSave 确保在sqlSave中设置fast=TRUE
  2. set auto commit off before running sqlSave: odbcSetAutoCommit(dbhandle, autoCommit = FALSE) and commit after sqlSave odbcEndTran(dbhandle, commit = TRUE) 在运行sqlSave之前设置自动提交关闭: odbcSetAutoCommit(dbhandle, autoCommit = FALSE)并在sqlSave之后提交odbcEndTran(dbhandle, commit = TRUE)

But, in my opinion, the real solution is BULK INSERT. 但是,在我看来,真正的解决方案是批量插入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载text或ntext SQL Server列的最快方法是什么? - What's the fastest way to load a text or ntext SQL Server column? 在有条件的情况下,在巨大的SQL Server表中计算总行数的最快方法是什么 - What is the fastest way to calculate total rows in a a huge SQL Server table with conditions 将大量数据插入分区表SQL Server的最快方法 - Fastest way to insert a huge amount of data into partitioned table SQL Server 从SQL Server数据库中获取大量数据的最快方法 - Fastest way to fetch huge amount of data from SQL Server database 将DataTable引入SQL Server的最快方法是什么? - What is the fastest way to get a DataTable into SQL Server? 更新巨大的 sql 表的最快方法 - Fastest way to update a huge sql table 将巨大数据集复制到SAS中服务器的最快方法 - The fastest way to copy a huge dataset to server in SAS 检查SQL Server服务器可用性的最快方法是什么? - What's the fastest way to check the availability of a SQL Server server? SQL Server-将表数据复制到另一台服务器的最快方法是什么? - SQL Server - What is the fastest way to copy table data to another server? 在SQL中选择单行的最快方法是什么? (SQL Server) - What is the fastest way to select a single row in SQL? (SQL Server)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM