Click to See Complete Forum and Search --> : How to set a column to be auto numbered?
ZhiYi
January 23rd, 2006, 12:21 AM
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?
dglienna
January 23rd, 2006, 12:25 AM
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.
GuOddian
January 23rd, 2006, 01:15 AM
Or, you could just use the inbuilt auto number flag of SQL Server.
exterminator
January 23rd, 2006, 01:30 AM
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 (http://www.sqlteam.com/item.asp?ItemID=8003) and IDENTITY (property) (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ia-iz_3iex.asp). Hope this helps. Regards.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.