Create table syntax not working in hsql

前端 未结 1 900
囚心锁ツ
囚心锁ツ 2021-02-07 20:28

I am new to hsqldb. I am developing simple application to get the some input from user. So Searched for embedded database and found hsqldb is the solution for my requirement.

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-07 21:01

    Use INT or INTEGER without specify the field length as it is not required for Int type fields. It is required for VARCHAR and DECIMALetc. type fields.

     CREATE TABLE  company (
       comp_name varchar(100) NOT NULL,
       comp_id int
     );
    

    To auto increment:

     ALTER TABLE company ALTER COLUMN comp_id 
     SET GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1);
    

    Alternatively:

     CREATE TABLE  company (
       comp_name varchar(100) NOT NULL,
       comp_id int GENERATED BY DEFAULT AS IDENTITY 
                                             (START WITH 1, INCREMENT BY 1) NOT NULL
     );
    

    You may also add the PRIMARY_KEY as below:

     CREATE TABLE  company (
       comp_name varchar(100) NOT NULL,
       comp_id INTEGER NOT NULL,
       PRIMARY KEY (comp_id)
     );
    

    0 讨论(0)
提交回复
热议问题