Search code examples
sqloracle-databasesql-updatealter-table

How to I create a new column in a table and add values to it


I have to create a new column in my table called Raise that has a 20% raise from the values of the SAL column, here's what I have so far:

SELECT ENAME,EMPNO, JOB, SAL from emp
ALTER TABLE emp
ADD Raise (INTEGER)
ALTER TABLE emp
Raise=SAL+SAL*0.20

Im not too sure what Im doing wrong here


Solution

  • Assuming that you are using Oracle (because your table looks like EMP from the SCOTT schema), is this what you want?

    alter table emp add raise number;
    update emp set raise = sal * 1.2;
    

    Note that if you want to increase something by 20%, then you probably want the result to be numeric rather than integer.