After some testing I realized that the support of database constraints is partial
and therefore potentially dangerous!
If I continue my example with statement
DELETE FROM B WHERE AID = 1;
the statement goes through
but now the table C is in violation of constraint DB_CONSTRAINT CHECK.
and executing a statement like
UPDATE C SET AID = 1 WHERE AID = 1
throws a constraint violation.

- rami

31.8.2011 19:20, Rami Ojares kirjoitti:
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