创建表语法在hsql中不起作用 [英] Create table syntax not working in hsql
问题描述
我是hsqldb的新手。我正在开发一个简单的应用程序,以从用户那里获取一些输入。因此,搜索嵌入式数据库并发现hsqldb是满足我要求的解决方案。
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.
我有一些create table语法,但是会引发异常。
I have some create table syntax but it throws exception.
(此查询通过使用Netbeans数据库服务执行)
(This Query executed by using Netbeans Database services)
查询:
CREATE TABLE company (
comp_name varchar(100) NOT NULL,
comp_id int(40) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (comp_id)
);
或
CREATE TABLE company (
comp_name varchar(100) NOT NULL,
comp_id int(40) NOT NULL IDENTITY
);
hsql db引发错误:
hsql db throws the error :
Error code -5581, SQL state 42581: unexpected token: ( : line: 3
Line 2, column 1
Execution finished after 0 s, 1 error(s) occurred.
请帮助我。.
谢谢。.
欢呼...!
推荐答案
使用 INT或INTEGER
,无需指定字段长度,因为对于Int类型的字段则不需要此字段长度。 code> VARCHAR 和 DECIMAL
等类型字段。
Use INT or INTEGER
without specify the field length as it is not required for Int type fields. It is required for VARCHAR
and DECIMAL
etc. type fields.
CREATE TABLE company (
comp_name varchar(100) NOT NULL,
comp_id int
);
要自动递增:
ALTER TABLE company ALTER COLUMN comp_id
SET GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1);
或者:
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
);
您还可以如下添加PRIMARY_KEY:
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)
);
这篇关于创建表语法在hsql中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!