Can someone please explain this very simple problem to me

  • Here is my sql statement:

    INSERT INTO DatabaseBackupHistory (Information) Values ('OK')

    Here is the error I'm receiving:

    Cannot insert the value NULL into column 'RunDT', table 'BackupDW.dbo.DatabaseBackupHistory'; column does not allow nulls. INSERT fails.

    Why is the statement attempting to insert into RunDT?

  • nvm, i'm an idiot. I need some coffee

  • Is RunDT in your table or is there a trigger on the table?

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • 1 of 2 things:

    1. You have a trigger on your table that is attempting to do stuff on insert or

    2. (More Likely) You have a column named RunDT in your table that is set to Not NULL and which does not have a default value.

    My guess is that the RunDT column in your table is the Run Date and you need to ensure that it has a value. I would suggest that you put a default value of GetDate() into the column's definition, thereby allowing you to use the INSERT command exactly as written - unless you have a few more NOT NULL columns to contend with.

  • Please provide the DDL for the table.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • jshurak (5/25/2011)


    nvm, i'm an idiot. I need some coffee

    I think this means that he figured out the problem... like include all columns in the insert!

  • Ninja's_RGR'us (5/25/2011)


    jshurak (5/25/2011)


    nvm, i'm an idiot. I need some coffee

    I think this means that he figured out the problem... like include all columns in the insert!

    Or at least the ones that don't allow nulls and that don't have defaults...

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • WayneS (5/25/2011)


    Ninja's_RGR'us (5/25/2011)


    jshurak (5/25/2011)


    nvm, i'm an idiot. I need some coffee

    I think this means that he figured out the problem... like include all columns in the insert!

    Or at least the ones that don't allow nulls and that don't have defaults...

    That was my "fill in the blanks" answer for today. :hehe:

  • Ninja's_RGR'us (5/25/2011)


    WayneS (5/25/2011)


    Ninja's_RGR'us (5/25/2011)


    jshurak (5/25/2011)


    nvm, i'm an idiot. I need some coffee

    I think this means that he figured out the problem... like include all columns in the insert!

    Or at least the ones that don't allow nulls and that don't have defaults...

    That was my "fill in the blanks" answer for today. :hehe:

    :w00t:

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • No no no. It was simpler than that. Insert statements are for rows that don't already exist in the database......update statements are for rows that do already exist.

    A bit of a facepalm moment. Like I said....I needed coffee...I swear that was it

  • jshurak (5/26/2011)


    No no no. It was simpler than that. Insert statements are for rows that don't already exist in the database......update statements are for rows that do already exist.

    A bit of a facepalm moment. Like I said....I needed coffee...I swear that was it

    Even worse better than what I had imagined! :pinch:

  • Ninja's_RGR'us (5/26/2011)


    jshurak (5/26/2011)


    No no no. It was simpler than that. Insert statements are for rows that don't already exist in the database......update statements are for rows that do already exist.

    A bit of a facepalm moment. Like I said....I needed coffee...I swear that was it

    Even worse better than what I had imagined! :pinch:

    Oh, of course. Why, that's just so obvious! ;-):w00t:

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • As per your information provided

    Cannot insert the value NULL into column 'RunDT', table 'BackupDW.dbo.DatabaseBackupHistory'; column does not allow nulls. INSERT fails

    this is happening cause of in your table DatabaseBackupHistory, RUNDT is having not null constraint.

    and you are not providing value for that.

    check your table schema

    better to write insert script with all columns.

  • Hmmm. Someone else a tad slow on the uptake maybe ...? 😀

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply