I have a table SINVOICE and another table called SINVOICE_LINE.
I need to put all columns of SINVOICE into SINVOICE_LINE.
I have created the corresponding columns and was trying to copy the values. The primary key of SINVOICE is SINVOICE_CODE, while the primary key for SINVOICE_LINE is a composite key (SINVOICE_CODE, SINVOICE_LINE_NUMBER).
I wrote the following query:
INSERT INTO SINVOICE_LINE (sinvoice.ITINERARY_CODE)
SELECT sinvoice_line.ITINERARY_CODE
FROM SINVOICE
INNER JOIN sinvoice_line ON sinvoice.sinvoice_code = sinvoice_line.sinvoice_code;
I get this error:
Cannot insert the value NULL into column SINVOICE_CODE, table SINVOICE_LINE; column does not allow nulls. INSERT fails.
I do not understand why I’m getting this error as I am not trying to insert any value in SINVOICE_CODE column.
Thanks!!!
Looks like you need UPDATE instead of INSERT here.
Try that: