pgsql如何添加自增字段
1.在已经建好的表(student):内含id(int4),name(varchar)字段
ALTER TABLE "student" OWNER TO "postgres";
2.创建与表对应的自增序列
create SEQUENCE student_id_seq
start with 1 --从1开始自增
INCREMENT by 1 --每次自增加1
no MINVALUE --没有最小值
no MAXVALUE --没有最大值
CACHE 1;
alter table student_id_seq OWNER to postgres;
3.给字段添加自增序列
alter SEQUENCE student_id_seq owned by student.id; --不添加这句在导出的sql中id的sequence为null
alter table student alter column id set default nextval('student_id_seq'); --真正给student 的id字段赋予自增序列