What is the way to describe an autoincrement field in base?

I want to set up a table in Base using the sql editor.
What is the way to define an autoincrement primary key?

1 Like

Hello,

You do this with GENERATED BY DEFAULT AS IDENTITY. Example table creation:

HSQLDB v1.8 (embedded - default):

CREATE TABLE MYTEST (
   ID INT GENERATED BY DEFAULT AS IDENTITY,
   NAME      VARCHAR(100) NOT NULL,
   PRIMARY KEY (ID) 
);

HSQLDB 2.x (split DB):

CREATE TABLE MYTEST
(
   ID        INTEGER        GENERATED BY DEFAULT AS IDENTITY,
   NAME      VARCHAR(100),
   CHECK (PUBLIC."MYTEST"."ID" IS NOT NULL)
);

Then:

ALTER TABLE MYTEST
   ADD PRIMARY KEY (ID);

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

Note: HSQLDB documentation for v1.8 for this syntax found here.