Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Server 2008

Hi

I am new to SQL. I have been developing in Access for quite a while.
What data type is best to use for an ID column that is the equivalent to AutoNumber
in Access?
Avatar of sventhan
sventhan
Flag of United States of America image

ASKER CERTIFIED SOLUTION
Avatar of EvilPostIt
EvilPostIt
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

thanks very much
Avatar of Vivekvl
Vivekvl

Since you want equivalent to AutoNumber, going for sequence will be good option

Here is an excellent article on implementing sequence in SQL Server

http://blogs.msdn.com/b/sqlcat/archive/2006/04/10/sql-server-sequence-number.aspx

Using sequence you can achieve literally the same feature as AutoNumber in Access. With little effort sequence can be customized to have prefix/suffix in alphabets

If you just want unique ID, NEWID() function is the easiest option available. This will not have readability and order.
For order issues with the NEWID function, i would suggest using NEWSEQUENTIALID function instead. This can cause massive problems with you clustered indexes if they are based upon this otherwise.