且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将Excel表数据传输到SQL 2008R2的最快方法

更新时间:2022-11-06 20:35:39

没有最快的方法,因为它取决于许多因素.确保已配置和优化了SQL中的索引.许多索引将破坏插入/更新性能,因为每个插入都需要更新索引.确保仅与数据库建立一个连接,并且在操作过程中不要打开/关闭该数据库.当服务器处于最小负载时运行更新.您没有尝试过的唯一其他方法是使用ADO Command对象,然后发出直接INSERT语句.当使用记录集对象的"AddNew"方法时,请确保在插入的末尾仅发出一个"UpdateBatch"命令.除此之外,VBA的运行速度只能与接受输入的SQL Server一样快.

There is no single fastest way, as it's dependent on a number of factors. Make sure the indexes in SQL are configured and optimized. Lots of indexes will kill insert/update performance since each insert will need to update the index. Make sure you only make one connection to the database, and do not open/close it during the operation. Run the update when the server is under minimal load. The only other method you haven't tried is to use a ADO Command object, and issue a direct INSERT statement. When using the 'AddNew' Method of the recordset object, be sure to issue only one 'UpdateBatch' Command at the end of the inserts. Short of that, the VBA can only run as fast as the SQL server accepting the inputs.

好像您已经尝试了一切.在SQL Server中,还有一种称为大容量日志记录"的恢复模式,该模式可以减少向事务日志中写入大量内容的开销.可能是值得研究的东西.这可能很麻烦,因为它需要稍微摆弄数据库恢复模型,但这对您可能很有用.

Seems like you've tried everything. There is also what is known as 'Bulk-Logged' recovery mode in SQL Server, that reduces the overhead of writting so much to the transaction log. Might be something worth looking into. It can be troublesome since it requires fiddling with the database recovery model a bit, but it could be useful for you.