Home » Database, SQL10 March 2009

SQL Error: Cannot insert the value NULL into column… column does not allow nulls. INSERT fails.

Error description:

Cannot insert the value NULL into column ‘SourceId’, table ‘Advisory.dbo.AdvDocSource’; column does not allow nulls. INSERT fails.
The statement has been terminated. The ‘CompanyAdd’ procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.
——————————-

This error occurs because the ‘SourceId’ column in my table is primary key and it is set to not null. i.e. it doesn’t allow null entries. And I have not made it auto increment.

For making a table column auto increment:
– Go to server explorer.
– In Column Properties, go to Identity Specification.
– Go to (Is Identity) and make it ‘Yes’ from the selection list.

You are done. You also have the option for Identity Increment and Identity Seed.

The SQL Query is:
CREATE TABLE [yourTableName](SourceID int IDENTITY(1,1) NOT NULL, …

SQL

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Congphuoc Phan

    This error is also happen when we use Import Tool, I have got the same one even when I check Identity in Data Table. Finally I found that, if we check the Identity in Data Table, than we don’t use the checkbox “Enable identity insert” in the Edit Mapping popup window

  • Jose84254Pandy

    Thanks a lot, this really is a truly awsome article! I also can share my experience in filling forms. BTW, there is an online service through which you can fill out a NY UD-2, the fillable blank is here http://goo.gl/W2lZ6i