Insert statement not inserting value for one field in sql database

Rajesh Bargode 20 Reputation points
2024-04-18T10:13:16.03+00:00

I have one existing table, now I have added one new field. When I try to insert value in that field it's not insert that value. its storing null value.

This is very odd issue I am facing.

SQL Server Other
{count} votes

3 answers

Sort by: Most helpful
  1. Greg Low 1,980 Reputation points Microsoft Regional Director
    2024-04-18T12:27:41.1366667+00:00

    You will need to show some code for what you're trying to do.

    But with any SQL systems, each INSERT statement should include a list of columns that are being inserted. As long as the new column is in the list, and is provided with a value, there's no reason it would not be inserted.

    As a general hint, and unrelated to your question, try to avoid referring to a "null value". A column IS null. It doesn't have a null value. Being null means that is has no value.

    If the columns are in your INSERT statement and not being inserted, you'll need to give us some SQL code to look at (i.e. the table definition, and the INSERT statement)

    0 comments No comments

  2. LiHongMSFT-4306 31,566 Reputation points
    2024-04-19T02:39:17.8866667+00:00

    Hi @Rajesh Bargode

    I have one existing table, now I have added one new field. When I try to insert value in that field it's not insert that value. its storing null value.

    Since you added a new column, then you need to use UPDATE instead of INSERT INTO to insert value in that field.

    Like this: UPDATE YourTable SET New_Column = SomeValue

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  3. Olaf Helper 47,436 Reputation points
    2024-04-19T06:27:25.68+00:00

    now I have added one new field.

    I guess you are using EF = "Entity Framework" for data access?

    Then you have to update the EF model to get the new column available in your code.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.