Click here to Skip to main content
15,886,632 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello Everyone,

I need I need to create an auto incremental field in my new table in sql server 2000
This auto incremental field must be the primary key of the table.
How I can do it.

Thanks in advence!

Leonardo Ayala R.
Posted

Create a new table.
Add a field, make it integer, and set Identity to true.
For example:
SQL
CREATE TABLE [dbo].[MyTable](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UseName] [nvarchar](50) NOT NULL,
	[JoinDate] [datetime] NOT NULL,
	[Visits] [int] NOT NULL,
 CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
 
Share this answer
 
Take a look http://www.w3schools.com/sql/sql_autoincrement.asp
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900