Sql server 将XML数据迁移到Microsoft SQL Server 2016
我想将XML文件中的数据迁移到MS SQL Server 2016 我的表文件如下所示:Sql server 将XML数据迁移到Microsoft SQL Server 2016,sql-server,xml,xsd,Sql Server,Xml,Xsd,我想将XML文件中的数据迁移到MS SQL Server 2016 我的表文件如下所示: [propertyid], [type], [object], [keyname], [keyvalue] 1, community, Private Community, name, Private Community 2, community, Private Community, communityname, Private Community 3, community, Private
[propertyid], [type], [object], [keyname], [keyvalue]
1, community, Private Community, name, Private Community
2, community, Private Community, communityname, Private Community
3, community, Private Community, server, chip.xyz.com:423132
4, community, Private Community, windowtitle, Private Community
5, community, Private Community, websiteurl, http://something
DECLARE @xml XML=
'<?xml version="1.0" encoding="UTF-8"?>
<doc>
<object type="community">
<name>
Private Community
</name>
<communityname>
Private Community
</communityname>
<server>
chip.xyz.com:423132
</server>
<windowtitle>
Private Community
</windowtitle>
<websiteurl>
http://something
</websiteurl>
</object>
</doc>';
表中的数据将从XML映射,如下所示:
[propertyid], [type], [object], [keyname], [keyvalue]
1, community, Private Community, name, Private Community
2, community, Private Community, communityname, Private Community
3, community, Private Community, server, chip.xyz.com:423132
4, community, Private Community, windowtitle, Private Community
5, community, Private Community, websiteurl, http://something
DECLARE @xml XML=
'<?xml version="1.0" encoding="UTF-8"?>
<doc>
<object type="community">
<name>
Private Community
</name>
<communityname>
Private Community
</communityname>
<server>
chip.xyz.com:423132
</server>
<windowtitle>
Private Community
</windowtitle>
<websiteurl>
http://something
</websiteurl>
</object>
</doc>';
XML文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<object type="community">
<name>
<![CDATA[Private Community]]>
</name>
<communityname>
<![CDATA[Private Community]]>
</communityname>
<server>
<![CDATA[chip.xyz.com:423132]]>
</server>
<windowtitle>
<![CDATA[Private Community]]>
</windowtitle>
<websiteurl>
<![CDATA[http://something]]>
</websiteurl>
</object>
</doc>
有没有什么方法可以通过脚本或其他方式来实现,因为上面提到的XML只是我正在使用的大XML的一部分,并且有很多记录请像这样尝试:
[propertyid], [type], [object], [keyname], [keyvalue]
1, community, Private Community, name, Private Community
2, community, Private Community, communityname, Private Community
3, community, Private Community, server, chip.xyz.com:423132
4, community, Private Community, windowtitle, Private Community
5, community, Private Community, websiteurl, http://something
DECLARE @xml XML=
'<?xml version="1.0" encoding="UTF-8"?>
<doc>
<object type="community">
<name>
Private Community
</name>
<communityname>
Private Community
</communityname>
<server>
chip.xyz.com:423132
</server>
<windowtitle>
Private Community
</windowtitle>
<websiteurl>
http://something
</websiteurl>
</object>
</doc>';
这是新创建的表的内容
SELECT * FROM MyNewlyCreatedTable;
+------------+-----------+-------------------+---------------+---------------------+
| propertyid | type | object | keyname | keyvalue |
+------------+-----------+-------------------+---------------+---------------------+
| 1 | community | Private Community | name | Private Community |
+------------+-----------+-------------------+---------------+---------------------+
| 2 | community | Private Community | communityname | Private Community |
+------------+-----------+-------------------+---------------+---------------------+
| 3 | community | Private Community | server | chip.xyz.com:423132 |
+------------+-----------+-------------------+---------------+---------------------+
| 4 | community | Private Community | windowtitle | Private Community |
+------------+-----------+-------------------+---------------+---------------------+
| 5 | community | Private Community | websiteurl | http://something |
+------------+-----------+-------------------+---------------+---------------------+
只是为了测试
--CleanUp
DROP TABLE MyNewlyCreatedTable;
这有帮助吗