简体   繁体   English

将分层SQL Server数据迁移到Azure CosmosDB

[英]Migrate hierarchical SQL Server data to Azure CosmosDB

I am exploring options to migrate data from SQL Server 2016 into CosmosDB with SQL API. 我正在探索使用SQL API将数据从SQL Server 2016迁移到CosmosDB的选项。 Source data is relational. 源数据是关系数据。 I need to join them and migrate to CosmosDB db in such a way that each row is migrated as a document. 我需要加入它们并以将每一行作为文档迁移的方式迁移到CosmosDB db。 Here is an example. 这是一个例子。

源表

I want to migrate these individual Product table rows combining it's related ProductSubCatalog table row something like below document. 我想结合其相关的ProductSubCatalog表行来迁移这些单独的Product表行,如下文档所述。

{              
          "ProductID": 970,                         
          "Name": "Touring-2000 Blue, 46",                         
          "ProductNumber": "BK-T44U-46",                         
          "MakeFlag": true,                         
          "FinishedGoodsFlag": true,                       
          "Color": "Blue",                                                       
          "ModifiedDate": "2014-02-08T10:01:36.827",                   
          "ProductSubCatalog": {                
                       "ProductSubcategoryID": 3,                      
                       "Name": "Touring Bikes"                                                                                 
          }                          
}                          

I tried DocumentDB Data Migration Tool with Source as “SQL” with below query. 我尝试使用DocumentDocument数据迁移工具将Source作为“ SQL”,并带有以下查询。

SELECT 
    [ProductID],P.[Name], [ProductNumber], [MakeFlag],  
    [FinishedGoodsFlag], [Color], [SafetyStockLevel], [ReorderPoint], 
    [StandardCost], [ListPrice],
    Ps.ProductSubcategoryID AS 'ProductSubCatalog.ProductSubcategoryID', 
    Ps.Name AS 'ProductSubCatalog.Name'   
FROM
    [Production].[Product] P 
LEFT JOIN
    Production.ProductSubcategory PS ON P.ProductSubcategoryID = ps.ProductSubcategoryID
FOR JSON PATH, ROOT('Product')

As the above query generates single JSON data for all rows in Product table, DocumentDB Data Migration Tool imports it as single document. 当上述查询为Product表中的所有行生成单个JSON数据时,DocumentDB数据迁移工具会将其导入为单个文档。 Does someone know other options to achieve this without writing custom application to query to SQL Server data, form JSON document and import it? 有人知道无需编写自定义应用程序即可查询SQL Server数据,形成JSON文档并将其导入的其他方法吗? Any suggestions and pointers will be appreciated. 任何建议和指针将不胜感激。

According to your description, I just followed Import from SQL Server and based on your tables to check this issue. 根据您的描述,我只是按照从SQL Server导入并根据您的表来检查此问题。

在此处输入图片说明

在此处输入图片说明

Note: You do not need to add FOR JSON PATH, ROOT('Product') within your query. 注意:您不需要在查询中添加FOR JSON PATH, ROOT('Product')

在此处输入图片说明

RESULT: 结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM