How to set a column to be auto numbered?
I am using visual studio 2005 with SQL server 2005 Express. Using visual studio, I created a table and would like to set the data type of the primary key column to be auto-numbered. However, there is no such thing in the data type list.
How do I enable a column in an existing table to be auto-numbered?
Re: How to set a column to be auto numbered?
You could keep the last used key in another table. You'd read it, add one, and then update the single field in the table for the next record. Then use the newest calculated key for your new record.
Re: How to set a column to be auto numbered?
Or, you could just use the inbuilt auto number flag of SQL Server.
Re: How to set a column to be auto numbered?
Quote:
Originally Posted by dglienna
You could keep the last used key in another table. You'd read it, add one, and then update the single field in the table for the next record. Then use the newest calculated key for your new record.
You would do that or something else only when the database server doesn't support Identity columns. SQL Server does!
Read up on Identity columns in SQL Server here - Understanding Identity Columns and IDENTITY (property). Hope this helps. Regards.