INSERT Statement error message references column I am not including in query

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I am using MSSQL 2008.



My INSERT statement is as follows:



INSERT INTO [DB1].[dbo].[SpotArtSong](ID)
SELECT SNG.S_ID
FROM [DB1].[dbo].[SpotArtSong] SPOT
INNER JOIN [DB2].[dbo].[nt-art] ART
ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
INNER JOIN [DB2].[dbo].[nt-sng] SNG
ON ART.Artist_ID = SNG.Artist_ID
AND left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
WHERE spot.BDSID is NULL


Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace. I have found the replacements and when looking over the full column results, I am happy with what the search would return from SNG.S_ID. I am trying to insert that one column into the one column on [DB1].[dbo].[SpotArtSong].



Essentially, I scrapped some data into [DB1].[dbo].[SpotArtSong] and I am matching it to some existing production data split among [DB2].[dbo].[nt-art] (ART) and [DB2].[dbo].[nt-sng] (SNG). I know the data in ART and SNG is correct, I am correlating it with the scrapped data in SPOT



The failure statement says:



Cannot insert the value NULL into column 'Artist', table 
'DB1.dbo.SpotArtSong'; column does not allow nulls. INSERT
fails.
The statement has been terminated.


I am not inserting anything there so I am not sure why it would fail. Plus, if I comment out the insert statement, the select statement does not return any NULL values.







share|improve this question

























    up vote
    1
    down vote

    favorite












    I am using MSSQL 2008.



    My INSERT statement is as follows:



    INSERT INTO [DB1].[dbo].[SpotArtSong](ID)
    SELECT SNG.S_ID
    FROM [DB1].[dbo].[SpotArtSong] SPOT
    INNER JOIN [DB2].[dbo].[nt-art] ART
    ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
    INNER JOIN [DB2].[dbo].[nt-sng] SNG
    ON ART.Artist_ID = SNG.Artist_ID
    AND left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
    WHERE spot.BDSID is NULL


    Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace. I have found the replacements and when looking over the full column results, I am happy with what the search would return from SNG.S_ID. I am trying to insert that one column into the one column on [DB1].[dbo].[SpotArtSong].



    Essentially, I scrapped some data into [DB1].[dbo].[SpotArtSong] and I am matching it to some existing production data split among [DB2].[dbo].[nt-art] (ART) and [DB2].[dbo].[nt-sng] (SNG). I know the data in ART and SNG is correct, I am correlating it with the scrapped data in SPOT



    The failure statement says:



    Cannot insert the value NULL into column 'Artist', table 
    'DB1.dbo.SpotArtSong'; column does not allow nulls. INSERT
    fails.
    The statement has been terminated.


    I am not inserting anything there so I am not sure why it would fail. Plus, if I comment out the insert statement, the select statement does not return any NULL values.







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am using MSSQL 2008.



      My INSERT statement is as follows:



      INSERT INTO [DB1].[dbo].[SpotArtSong](ID)
      SELECT SNG.S_ID
      FROM [DB1].[dbo].[SpotArtSong] SPOT
      INNER JOIN [DB2].[dbo].[nt-art] ART
      ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
      INNER JOIN [DB2].[dbo].[nt-sng] SNG
      ON ART.Artist_ID = SNG.Artist_ID
      AND left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
      WHERE spot.BDSID is NULL


      Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace. I have found the replacements and when looking over the full column results, I am happy with what the search would return from SNG.S_ID. I am trying to insert that one column into the one column on [DB1].[dbo].[SpotArtSong].



      Essentially, I scrapped some data into [DB1].[dbo].[SpotArtSong] and I am matching it to some existing production data split among [DB2].[dbo].[nt-art] (ART) and [DB2].[dbo].[nt-sng] (SNG). I know the data in ART and SNG is correct, I am correlating it with the scrapped data in SPOT



      The failure statement says:



      Cannot insert the value NULL into column 'Artist', table 
      'DB1.dbo.SpotArtSong'; column does not allow nulls. INSERT
      fails.
      The statement has been terminated.


      I am not inserting anything there so I am not sure why it would fail. Plus, if I comment out the insert statement, the select statement does not return any NULL values.







      share|improve this question











      I am using MSSQL 2008.



      My INSERT statement is as follows:



      INSERT INTO [DB1].[dbo].[SpotArtSong](ID)
      SELECT SNG.S_ID
      FROM [DB1].[dbo].[SpotArtSong] SPOT
      INNER JOIN [DB2].[dbo].[nt-art] ART
      ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
      INNER JOIN [DB2].[dbo].[nt-sng] SNG
      ON ART.Artist_ID = SNG.Artist_ID
      AND left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
      WHERE spot.BDSID is NULL


      Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace. I have found the replacements and when looking over the full column results, I am happy with what the search would return from SNG.S_ID. I am trying to insert that one column into the one column on [DB1].[dbo].[SpotArtSong].



      Essentially, I scrapped some data into [DB1].[dbo].[SpotArtSong] and I am matching it to some existing production data split among [DB2].[dbo].[nt-art] (ART) and [DB2].[dbo].[nt-sng] (SNG). I know the data in ART and SNG is correct, I am correlating it with the scrapped data in SPOT



      The failure statement says:



      Cannot insert the value NULL into column 'Artist', table 
      'DB1.dbo.SpotArtSong'; column does not allow nulls. INSERT
      fails.
      The statement has been terminated.


      I am not inserting anything there so I am not sure why it would fail. Plus, if I comment out the insert statement, the select statement does not return any NULL values.









      share|improve this question










      share|improve this question




      share|improve this question









      asked Aug 7 at 15:26









      chris dorn

      1083




      1083




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          The table SpotArtSong which you are trying to insert some records has at least these columns:



          • ID

          • Artist

          You are just supplying a value for ID, but column Artist has a NOT NULL constraint. When you don't supply a value for a column (by omitting it from the INSERT list), NULL is inserted by default unless there is a DEFAULT constraint. Because this column doesn't allow NULL values, the insert statement fails.



          Either supply a value for the Artist column (and any other column that is NOT NULL) or change the NOT NULL constraint on that column.



          To supply the artist name, add the Artist column name to the INSERT and supply a value through the SELECT, like the following:



          INSERT INTO [DB1].[dbo].[SpotArtSong](
          ID,
          Artist)
          SELECT
          ID = SNG.S_ID,
          Artist = ART.Artist_Name
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL


          To change the NOT NULL constraint use ALTER TABLE (note the lack of NOT NULL at the end):



          ALTER TABLE [DB1].[dbo].[SpotArtSong] ALTER COLUMN Artist VARCHAR(100)



          Althought it seems to me that you are actually trying to do an UPDATE instead of an INSERT:



          UPDATE SPOT SET
          ID = SNG.S_ID
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL





          share|improve this answer





















          • I had no idea that was even possible. To select out the data I need and say set this column equal to this other. Exactly what I needed, thanks.
            – chris dorn
            Aug 7 at 18:01

















          up vote
          2
          down vote














          Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace.




          Then why are you inserting whole new rows?



          The insert statement inserts new rows.



          You're telling the database to create new rows containing only the ID values that you're going to supply. The database is [rightly] objecting because the Artist column must have a value and, in the values you're supplying, there isn't one.



          The update statement updates existing rows.



          I think that's the one you need.






          share|improve this answer





















          • I did need an update statement, thanks for your help.
            – chris dorn
            Aug 7 at 18:01










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "182"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f214296%2finsert-statement-error-message-references-column-i-am-not-including-in-query%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          7
          down vote



          accepted










          The table SpotArtSong which you are trying to insert some records has at least these columns:



          • ID

          • Artist

          You are just supplying a value for ID, but column Artist has a NOT NULL constraint. When you don't supply a value for a column (by omitting it from the INSERT list), NULL is inserted by default unless there is a DEFAULT constraint. Because this column doesn't allow NULL values, the insert statement fails.



          Either supply a value for the Artist column (and any other column that is NOT NULL) or change the NOT NULL constraint on that column.



          To supply the artist name, add the Artist column name to the INSERT and supply a value through the SELECT, like the following:



          INSERT INTO [DB1].[dbo].[SpotArtSong](
          ID,
          Artist)
          SELECT
          ID = SNG.S_ID,
          Artist = ART.Artist_Name
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL


          To change the NOT NULL constraint use ALTER TABLE (note the lack of NOT NULL at the end):



          ALTER TABLE [DB1].[dbo].[SpotArtSong] ALTER COLUMN Artist VARCHAR(100)



          Althought it seems to me that you are actually trying to do an UPDATE instead of an INSERT:



          UPDATE SPOT SET
          ID = SNG.S_ID
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL





          share|improve this answer





















          • I had no idea that was even possible. To select out the data I need and say set this column equal to this other. Exactly what I needed, thanks.
            – chris dorn
            Aug 7 at 18:01














          up vote
          7
          down vote



          accepted










          The table SpotArtSong which you are trying to insert some records has at least these columns:



          • ID

          • Artist

          You are just supplying a value for ID, but column Artist has a NOT NULL constraint. When you don't supply a value for a column (by omitting it from the INSERT list), NULL is inserted by default unless there is a DEFAULT constraint. Because this column doesn't allow NULL values, the insert statement fails.



          Either supply a value for the Artist column (and any other column that is NOT NULL) or change the NOT NULL constraint on that column.



          To supply the artist name, add the Artist column name to the INSERT and supply a value through the SELECT, like the following:



          INSERT INTO [DB1].[dbo].[SpotArtSong](
          ID,
          Artist)
          SELECT
          ID = SNG.S_ID,
          Artist = ART.Artist_Name
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL


          To change the NOT NULL constraint use ALTER TABLE (note the lack of NOT NULL at the end):



          ALTER TABLE [DB1].[dbo].[SpotArtSong] ALTER COLUMN Artist VARCHAR(100)



          Althought it seems to me that you are actually trying to do an UPDATE instead of an INSERT:



          UPDATE SPOT SET
          ID = SNG.S_ID
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL





          share|improve this answer





















          • I had no idea that was even possible. To select out the data I need and say set this column equal to this other. Exactly what I needed, thanks.
            – chris dorn
            Aug 7 at 18:01












          up vote
          7
          down vote



          accepted







          up vote
          7
          down vote



          accepted






          The table SpotArtSong which you are trying to insert some records has at least these columns:



          • ID

          • Artist

          You are just supplying a value for ID, but column Artist has a NOT NULL constraint. When you don't supply a value for a column (by omitting it from the INSERT list), NULL is inserted by default unless there is a DEFAULT constraint. Because this column doesn't allow NULL values, the insert statement fails.



          Either supply a value for the Artist column (and any other column that is NOT NULL) or change the NOT NULL constraint on that column.



          To supply the artist name, add the Artist column name to the INSERT and supply a value through the SELECT, like the following:



          INSERT INTO [DB1].[dbo].[SpotArtSong](
          ID,
          Artist)
          SELECT
          ID = SNG.S_ID,
          Artist = ART.Artist_Name
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL


          To change the NOT NULL constraint use ALTER TABLE (note the lack of NOT NULL at the end):



          ALTER TABLE [DB1].[dbo].[SpotArtSong] ALTER COLUMN Artist VARCHAR(100)



          Althought it seems to me that you are actually trying to do an UPDATE instead of an INSERT:



          UPDATE SPOT SET
          ID = SNG.S_ID
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL





          share|improve this answer













          The table SpotArtSong which you are trying to insert some records has at least these columns:



          • ID

          • Artist

          You are just supplying a value for ID, but column Artist has a NOT NULL constraint. When you don't supply a value for a column (by omitting it from the INSERT list), NULL is inserted by default unless there is a DEFAULT constraint. Because this column doesn't allow NULL values, the insert statement fails.



          Either supply a value for the Artist column (and any other column that is NOT NULL) or change the NOT NULL constraint on that column.



          To supply the artist name, add the Artist column name to the INSERT and supply a value through the SELECT, like the following:



          INSERT INTO [DB1].[dbo].[SpotArtSong](
          ID,
          Artist)
          SELECT
          ID = SNG.S_ID,
          Artist = ART.Artist_Name
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL


          To change the NOT NULL constraint use ALTER TABLE (note the lack of NOT NULL at the end):



          ALTER TABLE [DB1].[dbo].[SpotArtSong] ALTER COLUMN Artist VARCHAR(100)



          Althought it seems to me that you are actually trying to do an UPDATE instead of an INSERT:



          UPDATE SPOT SET
          ID = SNG.S_ID
          FROM
          [DB1].[dbo].[SpotArtSong] SPOT
          INNER JOIN [DB2].[dbo].[nt-art] ART ON ART.Artist_Name LIKE SPOT.[Artist]+'%'
          INNER JOIN [DB2].[dbo].[nt-sng] SNG ON
          ART.Artist_ID = SNG.Artist_ID AND
          left(SNG.SONG_TITLE,10) = left(SPOT.[Song],10)
          WHERE
          spot.BDSID is NULL






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Aug 7 at 15:42









          EzLo

          1,8301316




          1,8301316











          • I had no idea that was even possible. To select out the data I need and say set this column equal to this other. Exactly what I needed, thanks.
            – chris dorn
            Aug 7 at 18:01
















          • I had no idea that was even possible. To select out the data I need and say set this column equal to this other. Exactly what I needed, thanks.
            – chris dorn
            Aug 7 at 18:01















          I had no idea that was even possible. To select out the data I need and say set this column equal to this other. Exactly what I needed, thanks.
          – chris dorn
          Aug 7 at 18:01




          I had no idea that was even possible. To select out the data I need and say set this column equal to this other. Exactly what I needed, thanks.
          – chris dorn
          Aug 7 at 18:01












          up vote
          2
          down vote














          Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace.




          Then why are you inserting whole new rows?



          The insert statement inserts new rows.



          You're telling the database to create new rows containing only the ID values that you're going to supply. The database is [rightly] objecting because the Artist column must have a value and, in the values you're supplying, there isn't one.



          The update statement updates existing rows.



          I think that's the one you need.






          share|improve this answer





















          • I did need an update statement, thanks for your help.
            – chris dorn
            Aug 7 at 18:01














          up vote
          2
          down vote














          Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace.




          Then why are you inserting whole new rows?



          The insert statement inserts new rows.



          You're telling the database to create new rows containing only the ID values that you're going to supply. The database is [rightly] objecting because the Artist column must have a value and, in the values you're supplying, there isn't one.



          The update statement updates existing rows.



          I think that's the one you need.






          share|improve this answer





















          • I did need an update statement, thanks for your help.
            – chris dorn
            Aug 7 at 18:01












          up vote
          2
          down vote










          up vote
          2
          down vote










          Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace.




          Then why are you inserting whole new rows?



          The insert statement inserts new rows.



          You're telling the database to create new rows containing only the ID values that you're going to supply. The database is [rightly] objecting because the Artist column must have a value and, in the values you're supplying, there isn't one.



          The update statement updates existing rows.



          I think that's the one you need.






          share|improve this answer














          Column [ID] on [DB1].[dbo].[SpotArtSong] has some null values that I am trying to replace.




          Then why are you inserting whole new rows?



          The insert statement inserts new rows.



          You're telling the database to create new rows containing only the ID values that you're going to supply. The database is [rightly] objecting because the Artist column must have a value and, in the values you're supplying, there isn't one.



          The update statement updates existing rows.



          I think that's the one you need.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Aug 7 at 15:43









          Phill W.

          27911




          27911











          • I did need an update statement, thanks for your help.
            – chris dorn
            Aug 7 at 18:01
















          • I did need an update statement, thanks for your help.
            – chris dorn
            Aug 7 at 18:01















          I did need an update statement, thanks for your help.
          – chris dorn
          Aug 7 at 18:01




          I did need an update statement, thanks for your help.
          – chris dorn
          Aug 7 at 18:01












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f214296%2finsert-statement-error-message-references-column-i-am-not-including-in-query%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491