更新时间:2023-02-12 09:14:11
创建一个新表。
添加一个字段,make它是整数,并将Identity设置为true。
例如:CREATE 表 [dbo]。[MyTable](
[Id] [ int ] IDENTITY ( 1 , 1 ) NOT NULL ,
[UseName] [ nvarchar ]( 50 ) NOT NULL ,
[JoinDate] [ datetime ] NOT NULL ,
[访问次数] [ 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 ]
看看http://www.w3schools.com/sql/sql_autoincrement。 ASP
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.
Create a new table.
Add a field, make it integer, and set Identity to true.
For example: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]
Take a look http://www.w3schools.com/sql/sql_autoincrement.asp