PostgreSQL primary key auto increment method
The PG primary key is auto-incremented, similar to oracle
1. First create the sequence
CREATE SEQUENCE test_c_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
[size=14px;] [/size]
[size=14px;][size=14px ;][size=14px;]2. If the table already exists, execute the following statement: [/size][/size][/size]
alter table test_c alter column id set default nextval('test_c_id_seq');
[size =14px;] [/size]
[size=14px;]3. If the table does not exist, then: [/size]
[size=14px;]create table table_name([/size]
[size=14px;] id int not null primary key default nextval('id_seq'),[/size]
[size=14px;] name varchar(30)
[/size]
[size=14px;])[/size]
All blogs have been transferred to leanote: http://blog.leanote.com/shiwei/
or: http://luoshiwei.me/
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326991431&siteId=291194637
Recommended
Ranking