Hi,

I always thought that H2 does not support database wide constraints except through triggers.
(namely constraints that can depend on the state of the whole database).
But I just realized that it does.
So I thought that this could be brought out more in the documentation because I think it is A BIG FEATURE!

Here I have a simple example to verify db constraints.

CREATE TABLE A (ID INT PRIMARY KEY);
CREATE TABLE B (AID INT REFERENCES A);
CREATE TABLE C (
    AID INT REFERENCES A,
    CONSTRAINT DB_CONSTRAINT CHECK(
        EXISTS(
            SELECT *
            FROM A
            JOIN B
            ON C.AID = A.ID AND A.ID = B.AID
        )
    )
);

INSERT INTO A VALUES(1);
INSERT INTO C VALUES(1);
INSERT INTO B VALUES(1);
INSERT INTO C VALUES(1);

The second insert will throw a constraint violation like it should.
Sweet.

- rami

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

Reply via email to