如何将主键设置为自动递增

时间:2023-01-25 09:37:53

I have table in Database and the primry key is 'ID', Just I want to ask how can I make it AUTOINCREMENT

我在数据库中有一个表,primry键是ID,我想问的是如何使它自动递增

I know that's esay Q, but I dont know how can I do it.

我知道那是esay Q,但我不知道该怎么做。

thanks

谢谢

6 个解决方案

#1


16  

There is a property "Identity Specification". Expand that one, you can chose Increment value, and Increment Seed

有一个属性“标识规范”。展开那个,你可以选择递增值,递增种子

#2


9  

In Sql Server define the column like this...

在Sql Server中定义列如下…

[PrimaryID] [int] IDENTITY(1,1) NOT NULL

Then you can add a constraint making it the primary key.

然后,您可以添加一个约束,使其成为主键。

#3


2  

MySQL: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
Oracle http://webxadmin.free.fr/article/oracle-autoincrement-columns-134.php
SQL Server: http://forums.devx.com/showthread.php?t=151539

MySQL: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Oracle http://webxadmin.free.fr/article/oracle- autoincre- 134.php SQL Server: http://forums.devx.com/showthread.phpt/1539

#4


2  

Since you listed ASP.NET, I'm going to assume you are running a SQL Server 2005/2008. If you want to use the GUI, then follow these steps:

既然你列出的ASP。NET,我假设你在运行一个SQL Server 2005/2008。如果您想使用GUI,请执行以下步骤:

  • Open the table in design view
  • 在设计视图中打开表。
  • Click on the "ID" column
  • 单击“ID”列
  • Confirm the type is an Int
  • 确认类型是Int类型
  • Select "Yes" under Identity Specification
  • 在标识规范下选择“Yes”

#5


0  

Go to column properties. There you have Identity specification properties. Expand the same. Next you set Is Identity as Yes. Then you can set Identity Increment value and Identity seed value as per requirement. By default it gets set to 1.

去列属性。这里有标识规范属性。扩大相同的。接下来你设置的是为Yes的恒等性。然后可以根据需要设置标识增量值和标识种子值。默认情况下,它被设置为1。

#6


0  

For Oracle it is a bit more non-trivial. You first have to create a sequence and then a trigger.

对于Oracle来说,这一点更为重要。首先要创建一个序列,然后是一个触发器。

#1


16  

There is a property "Identity Specification". Expand that one, you can chose Increment value, and Increment Seed

有一个属性“标识规范”。展开那个,你可以选择递增值,递增种子

#2


9  

In Sql Server define the column like this...

在Sql Server中定义列如下…

[PrimaryID] [int] IDENTITY(1,1) NOT NULL

Then you can add a constraint making it the primary key.

然后,您可以添加一个约束,使其成为主键。

#3


2  

MySQL: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
Oracle http://webxadmin.free.fr/article/oracle-autoincrement-columns-134.php
SQL Server: http://forums.devx.com/showthread.php?t=151539

MySQL: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Oracle http://webxadmin.free.fr/article/oracle- autoincre- 134.php SQL Server: http://forums.devx.com/showthread.phpt/1539

#4


2  

Since you listed ASP.NET, I'm going to assume you are running a SQL Server 2005/2008. If you want to use the GUI, then follow these steps:

既然你列出的ASP。NET,我假设你在运行一个SQL Server 2005/2008。如果您想使用GUI,请执行以下步骤:

  • Open the table in design view
  • 在设计视图中打开表。
  • Click on the "ID" column
  • 单击“ID”列
  • Confirm the type is an Int
  • 确认类型是Int类型
  • Select "Yes" under Identity Specification
  • 在标识规范下选择“Yes”

#5


0  

Go to column properties. There you have Identity specification properties. Expand the same. Next you set Is Identity as Yes. Then you can set Identity Increment value and Identity seed value as per requirement. By default it gets set to 1.

去列属性。这里有标识规范属性。扩大相同的。接下来你设置的是为Yes的恒等性。然后可以根据需要设置标识增量值和标识种子值。默认情况下,它被设置为1。

#6


0  

For Oracle it is a bit more non-trivial. You first have to create a sequence and then a trigger.

对于Oracle来说,这一点更为重要。首先要创建一个序列,然后是一个触发器。