Ask Your Question
0

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

asked 2017-12-22 18:10:21 +0200

ukwiz gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-12-22 18:28:06 +0200

Ratslinger gravatar image

updated 2017-12-22 18:46:10 +0200

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 ✔ (upper left area of answer). It helps others to know there was an accepted answer.

edit flag offensive delete link more

Comments

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

Ratslinger gravatar imageRatslinger ( 2017-12-22 18:49:59 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-12-22 18:10:21 +0200

Seen: 214 times

Last updated: Dec 22 '17