首先,让我说 SSIS 是您最好的选择。但是,要回答您提出的问题...
我不相信您可以到处创建新的 ID,尽管您可以,但您需要使用原始 ID 进行查找。
你能得到的最好的结果是一个表的插入语句。下面是SELECT
从 XML 示例中获取数据的代码示例:
declare @xml xml
set @xml='<People Key="1" FirstName="Bob" LastName="Smith">
<PeopleAddresses PeopleKey="1" AddressesKey="1">
<Addresses Key="1" Street="123 Main" City="St Louis" State="MO" ZIP="12345" />
</PeopleAddresses>
</People>
<People Key="2" FirstName="Harry" LastName="Jones">
<PeopleAddresses PeopleKey="2" AddressesKey="2">
<Addresses Key="2" Street="555 E 5th St" City="Chicago" State="IL" ZIP="23456" />
</PeopleAddresses>
</People>
<People Key="3" FirstName="Sally" LastName="Smith">
<PeopleAddresses PeopleKey="3" AddressesKey="1">
<Addresses Key="1" Street="123 Main" City="St Louis" State="MO" ZIP="12345" />
</PeopleAddresses>
</People>
<People Key="4" FirstName="Sara" LastName="Jones">
<PeopleAddresses PeopleKey="4" AddressesKey="2">
<Addresses Key="2" Street="555 E 5th St" City="Chicago" State="IL" ZIP="23456" />
</PeopleAddresses>
</People>
'
select t.b.value('./@Key', 'int') PeopleKey,
t.b.value('./@FirstName', 'nvarchar(50)') FirstName,
t.b.value('./@LastName', 'nvarchar(50)') LastName
from @xml.nodes('//People') t(b)
select t.b.value('../../@Key', 'int') PeopleKey,
t.b.value('./@Street', 'nvarchar(50)') Street,
t.b.value('./@City', 'nvarchar(50)') City,
t.b.value('./@State', 'char(2)') [State],
t.b.value('./@Zip', 'char(5)') Zip
from
@xml.nodes('//Addresses') t(b)
这样做是从 XML 中获取节点并解析数据。为了从人们那里获取关系 ID,我们使用 ../../ 来上链。