转载自:https://blog.51cto.com/13000661/2125889
方法一:
-- 这里的"test"专指postgre中的表空间(模式),默认的表空间是"public" DROP SEQUENCE if EXISTS "test"."testseq_id_seq"; CREATE SEQUENCE "test"."testseq_id_seq" INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1; DROP TABLE if EXISTS "test"."testtable"; CREATE TABLE "test"."testtable" ( "id" int4 DEFAULT nextval('testseq_id_seq'::regclass) NOT NULL, -- 表数据关联SEQUENCE,每次插入取nextval('testseq_id_seq')<pre name="code" class="sql"><pre name="code" class="sql">nextval('testseq_id_seq' "create_date" timestamp(6), "age" int4, "name" varchar(100), "grade" float4 ) WITH (OIDS=FALSE) ; ALTER TABLE "test"."testtable" ADD PRIMARY KEY ("id"); -- 插入数据,不需要写主键nextval('testseq_id_seq'); INSERT into "test"."testtable"(name) values('111'); -- 值数据(varchar)用单引号 -- 先创建sequence的第一个数据.. -- SELECT nextval('testseq_id_seq'); </pre><p></p>
nextval('chengdu_boundary_id_seq'::regclass)
方法二:
"id" SERIAL primary key NOT NULL,
#