Nick Brunt Nick Brunt - 3 months ago 34
SQL Question

Is it possible to copy all data from one table to another table, plus an extra column?

I have two tables that are very slightly different. Table A has 4 columns, and Table B has only 3. I want to copy all the data from Table B into Table A, but I also want to populate the extra column with the value

for every row.

This would work if not for the extra column:

insert into TABLEA (COL1, COL2, COL3) select COL1, COL2, COL3 from TABLEB;

Unfortunately, the extra column in Table A is not nullable, so I can't just run an update afterwards.

Thanks for any help!

lc. lc.
insert into TABLEA (COL1, COL2, COL3, COL4)
select COL1, COL2, COL3, 1
from TABLEB;