title: SQL Informix - adding foreign key
body: <p>I am struggling while creating new database tables with foreign keys in Informix DB. </p>
  
  <p>I need to migrate from one database to another. I am using <a href="https://dbeaver.io/about/" rel="nofollow noreferrer">DBeaver</a> as DB browsing and editing tool. I am trying to run script like this (I just changed names). The commands come from DBeaver DDL export itself, so this is how it <em>should</em> be.</p>
  
  <pre><code>DROP TABLE IF EXISTS eapp:test_table1;
  CREATE TABLE eapp:test_table1 (
      column1 smallint NOT NULL,
      PRIMARY KEY (column1) CONSTRAINT table1_pk
  );
  
  DROP TABLE IF EXISTS eapp:test_table2;
  CREATE TABLE eapp:test_table2 (
      column1 smallint NOT NULL,
      column2 varchar(100) NOT NULL,
      column3 smallint NOT NULL,
      column4 smallint,
      PRIMARY KEY (column1) CONSTRAINT table2_pk,
      FOREIGN KEY (column4) REFERENCES eapp:test_table1(column1) ON DELETE RESTRICT ON UPDATE RESTRICT CONSTRAINT table2_fk
  );
  </code></pre>
  
  <p>However, execution keeps crashing with a weird trimmed error message:</p>
  
  <p><a href="https://i.stack.imgur.com/i0PJK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i0PJK.png" alt="SQL execution error message"></a></p>
  
  <p>The language is Czech and it says something like <strong>"Syntax error. (Important notice: Database servers, that"</strong>. But the rest is trimmed even in detail, so I have no idea what is going on. </p>
  
  <p>Full stack:</p>
  
  <pre><code>org.jkiss.dbeaver.model.sql.DBSQLException: SQL Error [42000]: Chyba syntaxe. (Důležitá poznámka: Databázové servery, které
      at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:134)
      at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeStatement(SQLQueryJob.java:473)
      at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.lambda$0(SQLQueryJob.java:412)
      at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:148)
      at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.executeSingleQuery(SQLQueryJob.java:405)
      at org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob.extractData(SQLQueryJob.java:865)
      at org.jkiss.dbeaver.ui.editors.sql.SQLEditor$QueryResultsContainer.readData(SQLEditor.java:2833)
      at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.lambda$0(ResultSetJobDataRead.java:98)
      at org.jkiss.dbeaver.model.exec.DBExecUtils.tryExecuteRecover(DBExecUtils.java:148)
      at org.jkiss.dbeaver.ui.controls.resultset.ResultSetJobDataRead.run(ResultSetJobDataRead.java:96)
      at org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer$17.run(ResultSetViewer.java:3356)
      at org.jkiss.dbeaver.model.runtime.AbstractJob.run(AbstractJob.java:103)
      at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
  Caused by: java.sql.SQLException: Chyba syntaxe. (Důležitá poznámka: Databázové servery, které
      at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:413)
      at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3537)
      at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3853)
      at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2653)
      at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2569)
      at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2446)
      at com.informix.jdbc.IfxSqli.executeExecute(IfxSqli.java:2421)
      at com.informix.jdbc.IfxResultSet.b(IfxResultSet.java:393)
      at com.informix.jdbc.IfxStatement.a(IfxStatement.java:1326)
      at com.informix.jdbc.IfxStatement.executeImpl(IfxStatement.java:1296)
      at com.informix.jdbc.IfxStatement.c(IfxStatement.java:1007)
      at com.informix.jdbc.IfxStatement.execute(IfxStatement.java:893)
      at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.execute(JDBCStatementImpl.java:338)
      at org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCStatementImpl.executeStatement(JDBCStatementImpl.java:131)
      ... 12 more
  Caused by: java.sql.SQLException
      at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:413)
      at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3858)
      ... 23 more
  </code></pre>
  
  <p>I was unable to Google message like that, so I am trying to ask here, if anyone has some experience with Informix DB and could possibly give me some hints.</p>
  
  <p>I already tried to remove FK declaration from table creation and add it afterwards via <code>ALTER TABLE</code>, but it yields the same...</p>