使用Azure Cosmos DB数据迁移工具从SQL迁移时如何指定分区键
Azure Cosmos DB Data Migration Tool: Partition Key Allocation & Source Field Setup
How to Allocate Partition Keys During Migration
- First, lock in your target Cosmos DB container's partition key before starting the migration. This is non-negotiable because the tool uses this key to spread your data across Cosmos DB's partitions. Pick a field with high cardinality—like
customerId,orderId, ortenantId—to avoid hot partitions (where one partition gets all the traffic). - Make sure your source SQL data either has a matching field, or you can generate a valid value for the partition key. If you don’t have a ready-made field:
- Use the tool’s custom field mapping to combine multiple source columns (e.g., concatenate
RegionCodeandUserIdinto a single partition key value likeUS-12345) - Write a simple User-Defined Function (UDF) in the tool to generate the partition key on-the-fly during migration
- Use the tool’s custom field mapping to combine multiple source columns (e.g., concatenate
- In the tool’s target configuration, specify the partition key path (e.g.,
/customerId) for your Cosmos DB container. The tool will automatically route each source record to the correct partition based on the mapped value.
What to Fill in the Partition Key Field in the Source Info Module
The partition key field in the source information section should be the exact name of the column in your source SQL table that supplies the value for your Cosmos DB partition key.
For example:
- If your target Cosmos DB container uses
/customerIdas the partition key, and your source SQL table has a column namedCustomerIDholding the corresponding values, enterCustomerIDhere. - If you’re generating the partition key via a custom mapping or UDF, you can leave this field blank and handle the logic directly in the "Field Mappings" tab.
Quick Tips to Avoid Headaches
- Double-check that the source field’s data type plays nice with Cosmos DB—strings, numbers, and booleans work; skip complex types like arrays or objects.
- If you’re creating a new Cosmos DB container through the tool, set the partition key path correctly in the target settings first. You can’t change this after the container is created!
内容的提问来源于stack exchange,提问作者SaTyA
相关产品推荐
相关产品推荐

