如何装入巨大的(但简单)的分层的XML文件导入到SQL表导入到、巨大、简单、文件

2023-09-04 12:40:49 作者:有些爱永远只是演戏

我有一个非常大的(2.5GB,5500万节点)以下格式的XML文件:

I have a very large (2.5GB, 55 million node) XML file with the following format:

<TopNode>
    <Item id = "Something">
         <Link>A link</Link>
         <Link>Another link</Link>
         <Link>One More Link</Link>
    </Item>
    <Item id = "Something else">
         <Link>Some link</Link>
         <Link>You get the idea</Link>
    </Item>
  </TopNode>

我想这个扁平化到下列SQL表:

I want to flatten this into the following SQL table:

 -----------------------------------------
 |  Item          |          Link        |
 -----------------------------------------
 | Something      |  A link              |
 | Something      |  Another link        |
 | Something      |  One More Link       |
 | Something Else |  Some Link           |
 | Something Else |  You get the idea    |
 |----------------|----------------------|

我使用SQL2008,如果有差别。

I'm using SQL2008, if that makes a difference.

什么是最简单,最有效的方式(pferably使用SQL Server / .NET堆栈$ P $)从A点到B点,同时要注意所涉及的文件的大小?

What's the simplest, most efficient way (preferably using the SQL Server/.NET stack) to get from point A to point B, keeping in mind the size of the file involved?

推荐答案

我会使用的 XML大容量加载。这是一个很好的方法,因为它没有在整个文档中读取一次,它流吧。这也是相当快,并保持你与基于SQL Server工具坚持的要求。

I would use the XML Bulk Load. This is a nice approach because it doesn't read in the entire document at once, it streams it. It's also quite fast and keeps to your requirement of sticking with an SQL Server based tool.