Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoIncrement

Status
Not open for further replies.

wadewilson1

Programmer
Sep 10, 2002
23
0
0
US
I know this is probably out there already, but the search feature is down. Anyway

How do you create an autoincrementing field in a table. I know the answer is in front of my face, but it hasn't slapped me yet.
 
Code:
CREATE TABLE MyTable (
   AutoIncrementingField IDENTITY(1,1) PRIMARY KEY,
   ...
   )

Do you know how to use SQL Server Books Online? These help files are installed automatically with an installation of SQL Server. They are also available on the MSDN web site.

-------------------------------------
It is better to have honor than a good reputation.
(Reputation is what other people think about you. Honor is what you know about yourself.)
 
You can do it in Enterprise Manager (EM) by going into Design Mode (right click on the table or create a new table). Then add an integer column. Then below the list of columns are several properties, one of which is identity. Change that to Yes and you are good to go.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
That too! Thanks, Karl... my way was not the best for just getting the job done.

-------------------------------------
It is better to have honor than a good reputation.
(Reputation is what other people think about you. Honor is what you know about yourself.)
 
Thanks, I knew it was there just wasn't clicking for me.

I know it's in the books, but I could remember the Identity part of it so trying to find it was driving me insane.

Thanks again
 
oops. Must specify datatype.

Code:
AutoIncrementingField [red]int[/red] IDENTITY(1,1) PRIMARY KEY,

-------------------------------------
It is better to have honor than a good reputation.
(Reputation is what other people think about you. Honor is what you know about yourself.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top