I have a SQL table where a column (the PK) is an IDENTITY COLUMN: IDENTITY=TRUE, IDENTITY SEED = 1 and IDENTITY INCREMENT=1

It is my understanding that this column should auto increment but I must be doing something really basic wrong.

If I specify a value for the column (which I know is wrong) I get:

Msg 544, Level 16, State 1, Line 112
Cannot insert explicit value for identity column in table 'table_name' when IDENTITY_INSERT is set to OFF.

OK, so I don't specify the column (or value) at all and I get this:

Msg 515, Level 16, State 2, Line 112
Cannot insert the value NULL into column 'column_name', table 'table_name'; column does not allow nulls. INSERT fails.

I SHOULD know the answer to this, but I want the column to auto increment.

What am I doing wrong?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:
Don't use the column name in the insert statement

INSERT INTO (a,b,c,d) values (1,2,3,4)

As long as the ID column name doesn't appear in the list, you'll be fine.

Good Luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FarrellFritzAuthor Commented:

That is what I thought (and that is exactly what I did, but then I get the

Cannot insert the value NULL into column 'column_name', table 'table_name'; column does not allow nulls. INSERT fails.

FarrellFritzAuthor Commented:

Disregard my last reply.  You are SPOT ON correct.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.