Help Center > > Developer Guide> Database Quick Start> Creating and Managing Tables> Updating Data in a Table

Updating Data in a Table

Updated at: Mar 13, 2020 GMT+08:00

Data updating is performed to modify data in a database. You can update one row, all rows, or specified rows of data, or update data in a single column without affecting the data in the other columns.

The following types of information are required when the UPDATE statement is used to update a row:

  • Table name and column names of the data to be updated
  • New column data
  • Rows of the data to be updated

Generally, the SQL language does not provide a unique ID for a row of data. Therefore, it is impossible to directly specify the rows of the data to be updated. However, you can specify the rows by setting a condition that only the rows meet. If a table contains primary keys, you can specify a row by primary key.

For details about how to create a table and insert data to it, see Creating a Table and Inserting Data to a Table.

c_customer_sk in table customer_t1 must be changed from 9527 to 9876:

UPDATE customer_t1 SET c_customer_sk = 9876 WHERE c_customer_sk = 9527;

You can use a schema as a modifier of the table name. If no such modifier is specified, the table is located based on the default schema. In the statement, SET is followed by the target column and the new value of the column. The new value can be a constant or an expression.

For example, to increase all the values in the c_customer_sk column by 100:

UPDATE customer_t1 SET c_customer_sk = c_customer_sk + 100;

This statement does not include the WHERE clause, so all rows are updated. If the statement includes the WHERE clause, only the rows matching the clause are updated.

In the SET clause, the equal sign (=) indicates value setting. In the WHERE clause, the equal sign indicates comparison. WHERE does not represent an equation and can use other operators.

You can run an UPDATE statement to update multiple columns by specifying multiple values in the SET clause. For example:

UPDATE customer_t1 SET  c_customer_id = 'Admin', c_first_name = 'Local' WHERE c_customer_sk = 4421; 

After data has been updated or deleted in batches, a large number of deletion markers are generated in the data file. During query, data that is marked out by these deletion markers needs to be scanned as well. In this case, the query performance deteriorates after batch updates or deletions. If data needs to be updated or deleted in batches frequently, you are advised to periodically do VACUUM FULL to maintain the query performance.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?

Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel