Update data on table
18 May 2024 at 19:50
UPDATE
Β statement allows you to update data in one or more columns of one or more rows in a table.
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
In this syntax:
- First, specify the name of the table that you want to update data after theΒ
UPDATE
Β keyword. - Second, specify columns and their new values afterΒ
SET
Β keyword. The columns that do not appear in theΒSET
Β clause retain their original values. - Third, determine which rows to update in the condition of theΒ
WHERE
Β clause
Code:
UPDATE company SET salary = salary * 2 WHERE salary = 150000;
TheΒ WHERE
Β clause is optional. If you omit theΒ WHERE
Β clause, theΒ UPDATE
Β statement will update all the column values in the table.
Code:
UPDATE company SET salary = salary * 2
Summary :
- Use theΒ
UPDATE
Β statement to update data in one or more columns of a table. - Specify a condition in a WHERE clause to determine which rows to update data.
- Use theΒ
RETURNING
Β clause to return the updated rows from theΒUPDATE
Β statement