dplanet dplanet - 15 days ago 5
SQL Question

Multiply every entry in column by a fixed number in SQL

In SQL, say I have a table of the following layout:

id name age
1 george 12
2 tom 14
3 charles 19
4 henry 21
5 fiona 12
6 kate 14

If I discover that I've made a terrible inputting mistake, and that everybody is actually twice their age, is there a way to multiply the
column by 2 in one sweep instead of needing to painstakingly go through the whole column and edit each age individually (pretend I have 500 entries so manual work is out of the question).

Is there a SQL solution?


It's really easy:

UPDATE table SET age=age*2