Perl DBI - 加载到 SQL Serverl
我每天必须将一个大约 50MB 大小的文本文件加载到数据库中。我正在使用 Perl DBI 通过插入语句将文件加载到 SQL Server 中。它的性能不是很好,我想知道是否有更好/更快的方法从 DBI 加载到 SQL Server。
I have to load a text file into a database on a daily basis that is about 50MB in size. I am using Perl DBI to load the file using insert statements into a SQL Server. It is not very performant, and I was wondering if there are better/faster ways of loading from DBI into SQL Server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能应该使用
BULK INSERT
语句。没有理由你不能从 DBI 运行它。You should probably use the
BULK INSERT
statement. No reason you couldn't run that from DBI.在执行大型
INSERT
/UPDATE
操作时,禁用目标表上的任何索引、进行更改并重新启用索引通常很有用。这样,索引只需重建一次,而不是在每个INSERT
/UPDATE
语句运行后重建索引。(这也可以通过将原始表复制到未索引的临时表、在临时表上执行工作、添加索引、删除原始表以及重命名临时表以替换它,以零停机方式应用。)
When doing large
INSERT
/UPDATE
operations, it's generally useful to disable any indexes on the target table(s), make the changes, and re-enable the indexes. This way, the indexes only have to be rebuilt once instead of rebuilding them after eachINSERT
/UPDATE
statement runs.(This can also be applied in a zero-downtime way by copying the original table to an unindexed temp table, doing your work on the temp table, adding indexes, dropping the original table, and renaming the temp table to replace it.)
另一种加快速度的方法(如果尚未完成)是使用准备好的语句和绑定值。
Another way to speed things up (if not already done) is to use prepared statements and bind-values.