问题
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