SQL Server error 515

16,407

Looks like you need UPDATE instead of INSERT here.

Try that:

UPDATE  SINVOICE_LINE
SET ITINERARY_CODE = sinvoice.ITINERARY_CODE
from SINVOICE 
WHERE sinvoice.sinvoice_code = sinvoice_line.sinvoice_code; 
Share:
16,407
user1264578
Author by

user1264578

Updated on June 04, 2022

Comments

  • user1264578
    user1264578 almost 2 years

    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!!!