【问题标题】:How do i read scripts in h2 database如何读取 h2 数据库中的脚本
【发布时间】:2018-03-13 23:26:30
【问题描述】:

这是 schema.SQL 的脚本。当它到达脚本的 alter table 部分时显示错误:

 DROP TABLE IF EXISTS billing_address;

    CREATE TABLE billing_address (
      id bigint(20) NOT NULL AUTO_INCREMENT,
      billingAddressCity varchar(255),
      billingAddressCountry varchar(255),
      billingAddressName varchar(255),
      billingAddressState varchar(255),
      billingAddressStreet1 varchar(255),
      billingAddressStreet2 varchar(255),
      billingAddressZipCode varchar(255),
      order_id bigint  (20),
      PRIMARY KEY (id)
    );



    alter table user_role drop constraint if exists FKa68196081fvovjhkek5m97n3y foreign key (role_id) references role (roleid);
    alter table user_role add constraint FKa68196081fvovjhkek5m97n3y foreign key (role_id) references role (roleid);


> Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "ALTER TABLE BILLING_ADDRESS DROP CONSTRAINT IF EXISTS FKN9O6NQ40AQJYEBAOFKOLMGV69 FOREIGN[*] KEY (ORDER_ID) REFERENCES USER_ID  "; SQL statement:
alter table billing_address drop constraint if exists FKn9o6nq40aqjyebaofkolmgv69 foreign key (order_id) references user_id  [42000-196]

【问题讨论】:

  • 在到达问题行之前,有很多代码需要滚动浏览。您可能应该编辑掉脚本中不相关的部分,使其成为minimal, complete, verifiable example。我猜这就是这个问题被否决的原因。

标签: sql spring h2


【解决方案1】:

The syntax for drop constraint 不需要约束定义,只是名称。所以尝试替换

alter table billing_address drop constraint if exists FKn9o6nq40aqjyebaofkolmgv69
    foreign key (order_id) references user_id ;

只有

alter table billing_address drop constraint if exists FKn9o6nq40aqjyebaofkolmgv69 ;

对于以下其余的 drop 语句也是如此。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-27
    • 2016-03-02
    • 2019-12-17
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    相关资源
    最近更新 更多