Ask Your Question
0

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

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

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 reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-25 00:04:51.035523

1 Answer

Sort by » oldest newest most voted
0

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

Ratslinger gravatar image

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

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 +0100 )edit

Question Tools

1 follower

Stats

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

Seen: 583 times

Last updated: Dec 22 '17