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
 Primary Key-how to auto incriment

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2007-06-08 : 16:49:25
I can't for the life of me find out how to auto increment the primary key like you can in access. I want to use userIds that will auto increment as new users are added. Can you guys help me out at all?

As of now I used this code as an example. I'm using SQL server 2005

CREATE TABLE Customer
(SID integer PRIMARY KEY,
Last_Name varchar(30),
First_Name varchar(30));

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-08 : 16:53:55
Check out books on line if IDENTITY column suits your requirements.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-06-08 : 16:53:55
CREATE TABLE Customer
(SID integer IDENTITY(1,1) PRIMARY KEY,
Last_Name varchar(30),
First_Name varchar(30));
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-08 : 16:54:30


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

crugerenator
Posting Yak Master

126 Posts

Posted - 2007-06-08 : 16:59:31
wow, thanks for the super fast/helpful response!
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-06-08 : 21:53:24
It helps when you ask the easy questions!

e4 d5 xd5 Nf6
Go to Top of Page
   

- Advertisement -