Hi,

An idea just dawned on me.
Constraints can be commented:
COMMENT ON CONSTRAINT CONSTRAINT_NAME IS 'Here is the reason why this constraint is guarded';

This comment (if it exists) could be used in the exception message
making the error reporting much more user friendly.

Currently the exception message is
Check constraint violation: "CONSTRAINT_NAME: <SQL OF THE CONSTRAINT>
What I am proposing would be
Check constraint violation: "CONSTRAINT_NAME: <CONSTRAINT COMMENT>

And in case there is no comment the sql could be used.

What do you think?

- rami

On 08/31/2011 07:20 PM, Rami Ojares wrote:
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