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.
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));
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.