I have two tables I need to merge without creating a new view/table. Basically, I need to add only one column to an existing table taken from another table.
I need to get a table that would look just like table2 but with an additional column: programs_total. If there is no such id in the first column, I want the second column to have NULL. In this example, I want the raw with id=72_200 to have NULL in the programs_total column.
I tried the following script:
-- adding a new column
ALTER TABLE table2
ADD programs_total BIGINT NULL;
-- inserting new data
INSERT INTO table2 (programs_total)
SELECT programs_total
FROM table1
but it produces the following error:
Msg 515, Level 16, State 2, Line 4
Cannot insert the value NULL into column 'id', table 'stb.dbo.table2'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I suppose it tries to insert three new rows instead of joining the column with the existing ones. How do I tell it to join the column to the existing rows?
Or maybe I am doing something else wrong?

