Help Center/ GaussDB/ Developer Guide(Centralized_V2.0-8.x)/ FAQ/ How do I create an auto-increment column?
Updated on 2025-08-19 GMT+08:00
How do I create an auto-increment column?
Answer: GaussDB supports the creation of auto-increment columns. You can specify the SERIAL data type when creating a table.
Example:
gaussdb=#CREATE TABLE table_name(id serial, name varchar(20)); You can also use the following method:
-- Create a sequence. gaussdb=#CREATE SEQUENCE tbl_person_id_seq; -- Create the tbl_persion table. The value of the id column is automatically increased based on the sequence specified by tbl_person_id_seq. gaussdb=#CREATE TABLE tbl_persion( id int NOT NULL DEFAULT nextval('tbl_person_id_seq'::regclass), name varchar(20));
Parent topic: FAQ
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.