NOT NULL and what happens if a data type isn't given a value when a row is added

  • When a data type is defined as NOT NULL, what happens when new rows are created? Will a new row not be created (e.g., throw an error) if data is attempted to be inserted in that column/value that was declared/defined as NOT NULL?

  • If data is specified to be inserted into the not null column then that's fine. I suspect you meant what happens if data is not specified for a not null column.

    In that case..

    Msg 515, Level 16, State 2, Line 1

    Cannot insert the value NULL into column <column name>, table <table name>; column does not allow nulls. INSERT fails.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

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