As already mentioned, a simple update can be performed using:
UPDATE MyTable SET Column3 = Column1 + Column2;
However, storing caclulated values, especially for simple calculations, is not good practice (there are always exceptions, and this rule is not a rule), if column3 should always be the sum of column 1 and column2, then if your DBMS allows this, you can create a calculated column .
eg. In SQL Server:
ALTER TABLE MyTable ADD Column4 AS Column1 + Column2;
If your DBMS does not allow calculated columns, then you can create a view, so you only save the basic data, not the calculation (again, the syntax may vary depending on the DBMS):
CREATE VIEW myTableWithTotal AS SELECT Column1, Column2, Column1 + Column2 AS Column2 FROM MyTable
Any of these methods ensures that the value of column3 is updated even if columns1 or columns2 are updated.
GarethD
source share