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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 newid()

Author  Topic 

mikebird
Aged Yak Warrior

529 Posts

Posted - 2008-08-05 : 14:35:44
How do I set up a column to add incremental_by_1 INT values to each new row automatically? Not uniqueidentifier - just 1, 2, 3. Do I need to set up a trigger, or constraint, or put it in the table definition? It's been weeks since I did it. This column will be relied on by many other tables as a reference ID...

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-05 : 14:40:33
Just use the identity option.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-08-05 : 14:40:43
Look up IDENTITY in BOL
CREATE TABLE a(aCol int IDENTITY(1,1)) will do the trick

Jim
Go to Top of Page
   

- Advertisement -