SQL Server Newbie -- Auto Increment

I recently converted my Access 2007 to SQL Server Express 2012.  Just about everything is going fine ... except My Primary Key and Auto-increment.

In Access...I had a column usually called ID and this would auto increment as new records were added.  From a coding perspective I never touched it   However, now when I add new records I'm getting an error message that implies nothing is being inserted into the ID column and of course nulls are not allowed.  I went in (GUI) and changed the column to Primary Key and set Yes as Identity.  But this still didn't help.

BTW...code is in VBnet

Any ideas???


June 18th, 2012 1:11am

I think this link answers your question if not let me know

http://www.w3schools.com/sql/sql_autoincrement.asp

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2012 1:28am

I saw that article.  I'm not really creating a new table...I would like to use what I have in place.  It seems I should be able to use my existing ID column...perhaps that Alter Table?
June 18th, 2012 1:52am

I think you have 2 options,

1. Create a new table with identity & drop the existing table

2. Create a new column with identity & drop the existing column

check this

http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/04d69ee6-d4f5-4f8f-a115-d89f7bcbc032[^]

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2012 2:04am

Edit the table from sql server and change Identity property - yes from back end.

When you identity to yes then Identity seed value defaultly set to 1 but If data already exists then enter the proper Identity seed value.

otherwise you can drop the column and create new one with identity.

June 18th, 2012 3:02am

Hi,

What is the error you are getting? IDENTITY Works same as AUTOINCREMENT in Access. As you have already set the column as IDENTITY and NOT NULL, it should work fine. 

Can you show us the query that insert the data and DDL for the table?

Regards
Satheesh

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2012 9:30am

 

For Primary Key

Visit http://www.tutorialsqlserver.com/Create/Create-Primary-key-In-Sql-Server.htm

for Auto-increment.

Visit  http://www.tutorialsqlserver.com/Create/Auto-Increment-In-Sql-Server.htm

please let me know if any question about these topic.



July 6th, 2013 4:54am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics