Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create self-increasing id by postgresql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces postgresql how to create self-increasing id, the article is very detailed, has a certain reference value, interested friends must read!

The word "test" here refers specifically to the table space (schema) in postgre, and the default table space is "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,-- Table data association SEQUENCE. Take nextval (' testseq_id_seq') nextval ('testseq_id_seq' "create_date" timestamp (6), "age" int4, "name" varchar (6), "grade" float4) WITH (OIDS=FALSE); ALTER TABLE "test". "testtable" ADD PRIMARY KEY ("id") -- insert data without writing primary key nextval ('testseq_id_seq'); INSERT into "test". "testtable" (name) values (' 111');-- value data (varchar) in single quotation marks-- first create the first data of sequence.. -- SELECT nextval ('testseq_id_seq')

Nextval ('chengdu_boundary_id_seq'::regclass)

Method 2:

"id" SERIAL primary key NOT NULL

#

The above is all the content of the article "how postgresql creates self-increasing id". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report