Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 access autonumber = sql 2005?

Author  Topic 

bob123
Starting Member

16 Posts

Posted - 2006-10-30 : 17:02:42
Is there an equivalent in sql server2005 to msaccess autonumber?
I want to be able to insert values into a table and have the pk auto generated. Have tried using NEWID() function as default value for pk field but still have to stipulate NEWID() in the insert statement.
Is there a way around this?

B

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-30 : 17:08:54
use identity


KH

Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-10-30 : 22:19:16
since you mention newid(), I assume you are using guids for your pk column.

If that's the case (and if you really need to be using guids) you should look at newsequentialid(). it will give you a guid that's guaranteed to increase so that your pk index won't get fragmented.

However you shouldn't be using guids for the pk unless you really HAVE to. if ints suffice, use int identity as khtan suggests.


SqlSpec - a fast, cheap, and comprehensive data dictionary generator for
SQL Server 2000/2005 and Analysis Server 2005 - http://www.elsasoft.org
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-10-31 : 10:26:46
also be avare that this sequential guid is only server unique not world-wide unique.




Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -