AWS DMS从S3迁移至SQL Server:指定DATETIME2为目标数据类型
Got it, let's work through how to make sure your HireDate field from the S3 source maps to SQL Server 2014's DATETIME2 type during your AWS DMS migration. Here are the most reliable, straightforward approaches:
1. Use DMS Table Mapping Transformations (Recommended)
This is the built-in, low-fuss way to override default type mappings directly in your migration task:
- Open the AWS DMS Console, navigate to your migration task, and head to the Table mappings tab.
- Under Selection rules, double-check that your rule includes the
employeetable (tweak the rule if needed to target this specific table exclusively). - Click Add transformation rule, then pick
modify-columnas the rule type. - Fill in the transformation details:
- Schema name: Enter your target SQL Server schema (usually
dbo; leave blank if your selection rule already locks in the correct schema) - Table name:
employee - Column name:
HireDate - New data type:
datetime2(you can optionally add precision likedatetime2(7)for full sub-second accuracy, which matches SQL Server's default)
- Schema name: Enter your target SQL Server schema (usually
- Save the transformation, then restart your migration task if it’s already running.
This method overrides DMS’s default behavior (which would normally convert S3 TIMESTAMP to SQL Server DATETIME) and ensures HireDate lands exactly as DATETIME2.
2. Custom Column Mapping for CSV S3 Sources (If Applicable)
If your S3 data is stored as CSV files (instead of the structured JSON schema you shared), you can define explicit column types in your S3 source endpoint settings:
- Go to your S3 source endpoint in the DMS Console and click Edit.
- In the Extra connection attributes field, add this JSON configuration to map the
HireDatecolumn:{ "ColumnMapping": "[{\"TableName\":\"employee\",\"ColumnName\":\"HireDate\",\"ColumnType\":\"datetime2\"}]" } - Save the endpoint and re-run your migration task.
Quick Verification Step
After running a test migration, confirm the column type in SQL Server with this query:
SELECT COLUMN_NAME, DATA_TYPE, DATETIME_PRECISION FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'employee' AND COLUMN_NAME = 'HireDate';
You should see DATA_TYPE listed as datetime2, along with the precision you specified (if any).
内容的提问来源于stack exchange,提问作者fez

