How can I make a primary key as AUTOINCREMENT

时光毁灭记忆、已成空白 提交于 2020-01-20 05:00:07

问题


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

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

thanks


回答1:


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




回答2:


In Sql Server define the column like this...

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

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




回答3:


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




回答4:


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:

  • Open the table in design view
  • Click on the "ID" column
  • Confirm the type is an Int
  • Select "Yes" under Identity Specification



回答5:


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.




回答6:


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



来源:https://stackoverflow.com/questions/958120/how-can-i-make-a-primary-key-as-autoincrement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!