我如何读取h2数据库中的脚本

时间:2017-10-02 20:23:33

标签: sql spring h2

这是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]

1 个答案:

答案 0 :(得分:0)

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语句也类似。