我有一个错误,而一些sql语句在H2数据库。这些sql语句来自Hibernate SchemaExport:下面是sql语句:
create table CONTACTS (
person_id bigint not null,
contact_id bigint not null,
primary key (person_id, contact_id)
)
create table PERSON (
id bigint generated by default as identity,
FNAME varchar(55),
NAME varchar(55),
primary key (id)
)
alter table CONTACTS
add constraint UK_r5plahp7wqcsd47hscckyrxgd unique (contact_id)
alter table CONTACTS
add constraint FK_r5plahp7wqcsd47hscckyrxgd
foreign key (contact_id)
references PERSON
alter table CONTACTS
add constraint FK_90n1kse999lanaepr0v6hcgtv
foreign key (person_id)
references PERSON例如,这一行不能在H2中执行。
错误为:[ERROR] Caused by org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement : CREATE TABLE CONTACTS ( .... <<The same code from above>>
如何让这个SQL语句在H2中运行。
发布于 2013-06-19 17:34:35
我终于找到了我有语法错误的原因。
我实际上是在用Hibernate运行SchemaExport/SchemaUpdate,并且我没有在SQL语句中指定分隔符。
若要指定分隔符,请使用setDelimiter方法。例如,
export.setDelimiter(";");
update.setDelimiter(";");顺便说一句,要用SQL语句识别H2中的语法错误,可以在语句中找到*,它会给出错误所在的行。
发布于 2018-11-01 07:57:01
DDL语句必须在一行上。
https://stackoverflow.com/questions/17174543
复制相似问题