You can use the Normal Data Modify feature of Data Management Service (DMS) to change data in databases by executing SQL statements, such as INSERT, UPDATE, DELETE, and TRUNCATE. This feature allows you to initialize data, delete historical data, fix issues, or run a test. This topic describes how to change regular data in DMS.

Prerequisites

A database instance is managed in Stable Change or Security Collaboration mode in DMS. For more information, see Control modes.

Procedure

  1. Log on to the DMS console V5.0.
  2. In the top navigation bar, click Database Development. In the left-side navigation pane, choose Data Change > Normal Data Modify.
  3. In the Apply step of the Ticket Application wizard, set the parameters for submitting a data change ticket. The following table describes the parameters.
    Parameter Description
    Database The database for which you want to submit the ticket. You must select a database on which you have the change permissions.
    Associated Iterations Optional. The iteration to be associated with the data change. To select an iteration, click Select/Change Iteration. In the dialog box that appears, find the required iteration and click Associate in the Actions column.
    Reason Category The reason for the data change. This helps you find the ticket in subsequent operations.
    Note If you are a DMS administrator, you can modify reason categories on the Configuration Management page of the O&M module. For more information, see Configuration management.
    Business Background The purposes or objectives of the data change. This reduces unnecessary communication.
    Execution Method The execution method of the ticket. Valid values:
    • After Audit Approved, Order Submitter Execute
    • After Audit Approved, Auto Execute
    • Last Auditor Execute
    Note If you are a DMS administrator, you can modify execution methods on the Configuration Management page of the O&M module. For more information, see Configuration management.
    Affected Rows The estimated number of data rows that may be affected by the data change.
    SQL Statements for Change The SQL statements that are used for data change. You can use one of the following methods to specify SQL statements:
    • Text: Enter SQL statements in the SQL Text field.
    • Attachment: Click Upload a file to upload the file that stores the SQL statements used for data change.
    Note
    • Separate multiple SQL statements with semicolons (;).
    • DMS checks whether the syntax of the SQL statements is valid when you submit the ticket. If the syntax is invalid, you cannot submit the ticket.
    • The file to upload can be a TXT, ZIP, or SQL file. The size of the file cannot exceed 15 MB.
    SQL Statements for Rollback Optional. The SQL statements that are used for rollback. You can use one of the following methods to specify SQL statements:
    • Text: Enter SQL statements in the SQL Text field.
    • Attachment: Click Upload a file to upload the file that stores the SQL statements used for rollback.
    Note
    • The SQL statements that you specify for this parameter are used to roll back the data change.
    • The file to upload can be a TXT, ZIP, or SQL file. The size of the file cannot exceed 15 MB.
    Change Stakeholder Optional. The stakeholders involved in the data change. All the specified stakeholders can view the ticket details and assist in the approval process. Irrelevant users except for DMS administrators and database administrators (DBAs) cannot view the ticket details.
    Attachments Optional. The file used as an attachment of the ticket to add additional information about the data change.
  4. Click Submit.
    After you submit a ticket, the system automatically performs a precheck on the ticket. If the ticket fails to pass the precheck, modify the SQL statements as prompted and submit the ticket again.
  5. After the ticket passes the precheck, click Submit for Approval. In the Prompt message, click OK
    Note By default, data change tickets are approved by DBAs. For more information about how to change the default approval template, see Change the default approval template.
  6. After the ticket is approved, click Execute Change. In the Task Settings dialog box, set the parameters as required and click Confirm Execution.
    Note If you set the Execution Method parameter to After Audit Approved, Auto Execute in the Apply step, this step is automatically skipped.
    Parameter Description
    Execution Strategy Specifies whether to run the task for the ticket immediately or at a scheduled time. Valid values:
    • Running immediately: If you select this option and click Confirm Execution, DMS immediately runs the task.
    • Schedule: If you select this option, you need to specify a time point. After you click Confirm Execution, DMS runs the task at the scheduled time point.
    Transaction Control Specifies whether to enable transaction control. Default value: off. Valid values:
    • on: If an SQL statement fails to be executed, all the executed DML statements in the same transaction are rolled back. DDL statements cannot be rolled back.
    • off: The specified SQL statements are executed one by one. If an SQL statement fails to be executed, the transaction is stopped. The other executed SQL statements in the same transaction are not rolled back.
    Data Backup Specifies whether to back up data. Default value: on. Valid values:
    Note
    • Data backup is supported for only UPDATE and DELETE statements.
    • You cannot back up data for MongoDB or Redis databases.
    • on: DMS generates specific statements to back up the data that is affected when UPDATE or DELETE statements are executed.
      • If the database is a MySQL or MariaDB database, DMS generates a REPLACE INTO statement.
        Note The supported MySQL databases are databases in ApsaraDB RDS for MySQL, PolarDB for MySQL, ApsaraDB MyBase for MySQL, and PolarDB-X 1.0, and MySQL databases that are not on Alibaba Cloud.
      • If the database is not a MySQL or MariaDB database, DMS generates an INSERT statement.
    • off: DMS does not generate statements for data backup.
    Note The execution of SQL tasks is monitored by the checkpoints that are configured in security rules to control SQL execution. Examples of the checkpoints include Database lock timeout mechanism before SQL execution, Database load check before SQL execution, and sleep policy after SQL execution. To check the checkpoints that are configured in a security rule to control SQL execution, go to the details page of the security rule, and then click SQL execution control in the left-side pane. For more information about how to modify the default checkpoint settings, see Configure the control on SQL execution.
    • After the task is complete, you can click Details in the Actions column of the ticket to view the ticket execution status, number of times the task is run, number of affected rows, executed statements, and logs.
    • After the task is complete, you can go to the SQLConsole tab of the database to check whether the data change meets expectations.
  7. Optional:If the data change does not meet expectations, restore data by performing the following operations:
    1. In the Execute step of the Ticket Details wizard for the ticket, click Download Backup in the Actions column to download the backup file.
      A backup file contains the following information:
      • The original SQL statements that are executed to change data
      • The SELECT clause in the original SQL statements
      • The SQL statement that is used for data backup
      Example:
      /*
      [Database]:   rds@rm-bp144d5ky4l4rli0417****.mysql.rds.aliyuncs.com:3306[rds mysql]
      */
      
      /*
      [SQL]:
      
      
      UPDATE t_order
      SET product_id = 88
      WHERE id = 10054
      [BACKUP SQL]:    SELECT *
      FROM t_order
      WHERE id = 10054
      */
      REPLACE INTO `t_order`(`id`,`product_id`,`gmt_create`,`gmt_modified`,`customer_id`,`price`,`status`,`province`) VALUES
      (10054,81,'2021-12-14 09:44:44','2021-12-14 09:44:44',71,63.45,'Success','Hangzhou');
                                          
    2. Extract the SQL statement for data backup from the backup file. After you confirm that the statement is valid, submit a data change ticket to restore the database data based on the actual situation.
    Note If an improper UDPATE statement is executed for the data change and the system generates an INSERT statement for data backup, you must manually restore data.

Usage notes

  • After you submit a data change ticket for approval, you can close the ticket regardless of whether the ticket is approved or rejected. This prevents the task for the ticket from being accidentally executed after the ticket is approved.
  • We recommend that you submit tickets for data changes in the test environment. This way, the system checks the number of rows to be affected and generates a backup file for each data change. This allows you to restore data if the data change does not meet expectations.
    Note To ensure high R&D efficiency, you can specify that no approval is required for data change tickets in the test environment. For more information, see SQL Correct.
  • If you have configured logical databases, logical tables, and routing algorithms in DMS, you can submit a ticket to shard databases and partition tables at the same time. This way, you do not need to submit a ticket for each physical database or table.
    • If you have configured a routing algorithm, and a routing field is included in the SQL statement that is used to shard databases and partition tables, the routing algorithm routes the statement to the corresponding physical table for execution.
    • If you have not configured a routing algorithm, no routing field is included in the SQL statement, or the data type of the routing field does not match the data type that is specified in the routing algorithm, the SQL statement is executed on each table in each database one by one. This process takes a longer period of time.