PostgreSQL没有自动递增功能? [英] PostgreSQL No Auto Increment function?
问题描述
我有一个用Java编码的测试应用程序,用于在MySQL,PostgreSQL,Oracle和Firebird数据库中创建索引和非索引表(还有其他功能)。
I have a test application coded in Java for creating an indexed and non indexed table in a MySQL, PostgreSQL, Oracle and Firebird database (Amongst other things).
是否只是PostgreSQL不允许自动递增功能的一种情况?如果没有,使用索引索引的正常程序是什么?
Is it simply a case that PostgreSQL doesnt allow the auto increment feature? If not, what is the normal procedure for having an indexed coloumn?
预先感谢
推荐答案
您可以使用 <$ c PostgreSQL中的$ c> SERIAL 来生成自动递增字段,
You may use SERIAL
in PostgreSQL to generate auto increment field,
例如:-
CREATE TABLE user (
userid SERIAL PRIMARY KEY,
username VARCHAR(16) UNIQUE NOT NULL
)
这将创建用户ID作为索引的自动增量主键。
如果您不想将此作为主键,只需删除PRIMARY KEY。
This will create userid as auto-increment primary key indexed. If you don't want this as primary key, just remove PRIMARY KEY.
这篇关于PostgreSQL没有自动递增功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!