Create table syntax not working in hsql

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

I have create table syntax, but it throws an exception.

(This query is executed using Netbeans Database Services)

Request:

CREATE TABLE company ( comp_name varchar(100) NOT NULL, comp_id int(40) NOT NULL AUTO_INCREMENT, PRIMARY KEY (comp_id) ); 

or

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

hsql db produces an error:

 Error code -5581, SQL state 42581: unexpected token: ( : line: 3 Line 2, column 1 Execution finished after 0 s, 1 error(s) occurred. 

Please help me.

Thanks at Advance ..

Greetings ...

+8
java create-table hsqldb
source share
1 answer

Use INT or INTEGER without specifying the length of the field , as this is not required for fields of type Int. This is necessary for VARCHAR and DECIMAL , etc. enter the fields.

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

To auto zoom:

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

As an alternative:

  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 can also add PRIMARY_KEY as shown below:

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

All Articles