我怎样才能更有效地拆分桌子 [英] How can I split a table more efficently
问题描述
我正在尝试在数据表之间插入行。但是,我现在的方式非常低效,因为它需要花费大量的时间和内存才能完成整个过程。
这里是我如何使用我的代码的一个例子:
I am trying to insert rows between datatables. However, the way I have it now is very inefficient as it takes up a lot of time and memory to complete the process.
here is an example of how I am using my code:
For Each row As DataRow In temptable.Rows
Insert statement
select ID statement- for each iteration to show the number of rows has changed
5 more insert statements with the ID column number being used in the individual_ID column of each table.
Next
我根据他们分手列。我在每个表中使用Individual_ID,以便也选择相应的记录。
我想知道的是我可以使用批量复制做类似的事情,我可以导入到每个表并在添加行时插入Individual_ID,或者在其他地方插入方式?
我尝试了什么:
我试过使用
I am breaking up tables based upon their columns. I am using an Individual_ID in each table so that corresponding records will be selected as well.
What I want to know is can I do something similar with bulk copy where I can import to each table and have the Individual_ID inserted as rows are added, or there another way?
What I have tried:
I have tried to rule out insert statements by using
if dt.columns.contains then
声明。它确实改善了时间,但它仍然很慢。
statement. It does improve the time, however, it is still slow.
推荐答案
我认为你要做的是批量插入,带有IDENTITY列。 br $> b $ b
批量导入数据时保留标识值(SQL Server) Microsoft Docs [ ^ ]
这个包括升级:
sql server - 带有标识(自动增量)列的BULK INSERT - Stack Overflow [ ^ ]
I think what you want to do is "bulk insert" with an "IDENTITY" column.
Keep Identity Values When Bulk Importing Data (SQL Server) | Microsoft Docs[^]
This one includes "staging":
sql server - BULK INSERT with identity (auto-increment) column - Stack Overflow[^]
这篇关于我怎样才能更有效地拆分桌子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!