Autonumber in MSSQL

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I'm in the "Enterprise Manager" for this MSSQL trying to figure out how to do INSERT queries. When I run:

INSERT INTO Customer (Username)
VALUES ('hihi')
'

I get the error "...Cannot insert the value NULL into column id, table... column does not allow nulls. INSERT fails"

Now I assumed that the Customer table's id field was an autonumber (hopefully there is such thing in MSSQL), but if it's not, then that probably caused the problem. So is that statement correct? And how can I determine for sure if the id column on Customer is an autonumber? If autonumbers don't exist in MSSQL, how can you figure out what the next id should be?

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

It turned out that there was another table in the database that held the next number for the customer table. So I have to select it, then run my insert query using the number I pulled from the other table, and then do an update and add one to the number in the other table. Confusing!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.