简体   繁体   中英

Migrate hierarchical SQL Server data to Azure CosmosDB

I am exploring options to migrate data from SQL Server 2016 into CosmosDB with SQL API. 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. Here is an example.

源表

I want to migrate these individual Product table rows combining it's related ProductSubCatalog table row something like below document.

{              
          "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.

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. Does someone know other options to achieve this without writing custom application to query to SQL Server data, form JSON document and import it? 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.

在此处输入图片说明

在此处输入图片说明

Note: You do not need to add FOR JSON PATH, ROOT('Product') within your query.

在此处输入图片说明

RESULT:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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