Murray Brown
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks very much
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.
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.
http://msdn.microsoft.com/en-us/library/aa933196(v=sql.80).aspx