2013/6/17 Rami Ojares <[email protected]>:
> You can also model an enum with relational concepts.
> Let me show you.

I tried what you said and it mostly works. (Good enough for the moment
anyway.) And when I change the periods language to Dutch, the types
table is automatically updated. :-D

At the moment I have the following:
    CREATE TABLE periods (
        description     VARCHAR(10)     PRIMARY KEY
    );

    CREATE TABLE types (
        typeID          UUID            PRIMARY KEY,
        description     VARCHAR(50)     UNIQUE NOT NULL,
        typeGroupID     UUID            NOT NULL,
        ranking         SMALLINT,
        evalPeriod      VARCHAR(10)     NOT NULL DEFAULT 'daily'
REFERENCES periods ON UPDATE CASCADE,
        FOREIGN KEY     (typeGroupID)   REFERENCES typeGroups(typeGroupID)
    );

    INSERT INTO periods
    (description)
    VALUES
    ('daily'),
    ('weekly'),
    ('monthly'),
    ('yearly')
    ;

>
> CREATE TABLE PERIOD (
>     PERIOD_ID IDENTITY PRIMARY KEY,
>     PERIOD_NAME VARCAHR(10) UNIQUE,
>     MAYBE_SOME_OTHER_PERIOD_RELATED_ATTRIBUTE VARCHAR
> );
> Now insert the possible periods as tuples into the relation period.
> INSERT INTO PERIOD VALUES (DEFAULT, 'daily', '...');

What do you mean with DEFAULT?


> ...
> Then define a constraint that prohibits inserts and updates to table PERIOD
> This can be done utilizing H2's triggers.

I'll have to look into that.


> Then when you want to use the period enum as type of an attribute define it
> like this
>
> MY_ATTRIBUTE BIGINT REFERENCES PERIOD ON UPDATE CASCADE
>
> Now you can relate data to enum values and all changes are propagated
> automatically throughout the database.

I saw that. Very need indeed.

-- 
Cecil Westerhof

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to