Noel,

    Sorry for the confusion. Here is the testcase (with embedded SQL):

package org.bitbucket.cowwoc.h2invalidcheck;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class App {

public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("org.h2.Driver");
Connection connection = DriverManager.getConnection("jdbc:h2:mem:test1;DB_CLOSE_DELAY=120", "sa", "");
        Statement statement = connection.createStatement();
        statement.executeUpdate("create table companies(id identity)");
        statement.executeUpdate("create table departments(id identity, "
                + "company_id bigint not null, "
                + "foreign key(company_id) references companies(id))");
statement.executeUpdate("create table connections (id identity, company_id bigint not null, "
                + "first bigint not null, second bigint not null, "
                + "foreign key (company_id) references companies(id), "
                + "foreign key (first) references departments(id), "
                + "foreign key (second) references departments(id), "
+ "check (select departments.company_id from departments, companies where "
                + "departments.id in (first, second)) = company_id);");

        statement.executeUpdate("insert into companies(id) values(1)");
        statement.executeUpdate("insert into departments(id, company_id) "
                + "values(10, 1)");
        statement.executeUpdate("insert into departments(id, company_id) "
                + "values(20, 1)");
statement.executeUpdate("insert into connections(id, company_id, first, second) "
                + "values(100, 1, 10, 20)");
        connection.commit();
    }
}

Thanks,
Gili

On 11/06/2013 4:53 AM, Noel Grandin wrote:
I see trigger stuff, but nothing about CHECK constraints.

If I don't see a simple self-contained SQL script in the next email, I will stop trying to fix this.

On 2013-06-10 18:22, cowwoc wrote:
On 10/06/2013 12:21 PM, Noel Grandin wrote:
Nope, there is no zip link when I go to that page.

How about you just post the SQL script using email?

Sorry. Here is a direct link: https://bitbucket.org/cowwoc/h2invalidcheck/get/default.zip

Gili


--
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to