All Products
Search
Document Center

:A prompt appears when you execute a DML statement through the Data change or SQLConsole "Data truncation:Data too long"

Last Updated:Feb 08, 2021

Issue

When you execute a DML statement of an apsaradb RDS for MySQL instance or a user-created MySQL database (ECS-hosted database or IDC-hosted database) by using data changes or the SQLConsole, a truncation error is reported. The following error message is returned.

Data truncation:Data too long

Cause

The length specified to write the field value exceeds the corresponding field length defined by the table schema. In this case, the data cannot be written correctly, and a truncation error is reported.

Solutions

Check the definition of the table structure and DML requirements, and confirm that any of the following methods is used according to the actual situation:

  • Adjust the length of this field in the table structure:
    • Adjust the length of a field in the DMS console:
      1. Log on to the DMS console and select the target instance. Select the target database, right-click the destination table, and choose edit table structure from the shortcut menu.
      2. Click column information to adjust the column length.
    • Execute SQL statements to adjust the length of a field:
      ALTER TABLE `[$Table]` MODIFY COLUMN `[$Field]` [$Type]([$Num]);
      Note:
      • [$Table] is the name of the Table to be adjusted.
      • [$Field] is the name of the Field to be adjusted.
      • [$Type] is the field Type.
      • [$Num] is the length of the field.
  • Modify the types of fields for which DML statements are executed to make their lengths meet requirements.

Scope

  • Data Management (DMS)
  • ApsaraDB RDS
    note: This topic applies to apsaradb RDS for MySQL instances or user-created MySQL databases (user-created databases in ECS instances or user-created databases in on-premises data centers).