[thelist] Constraint/trigger help

Bill Moseley moseley at hank.org
Fri May 18 01:17:23 CDT 2007


Say I have a mail reader application where people can create their own
mailboxes (folders).  So I have a table:

    create table mailbox (
        id       integer,
        name     text,
        owner    int references user(id)
    );

So, now the user table should store their default mailbox
(ignoring that I've referenced user above before defining it)

    create table user (
        id               integer,
        name             text,
        email            text,
        default_mailbox  integer references mailbox(id)
    );

How can I ensure (in the database) that default_mailbox references a
mailbox that has its owner set to the same user?  Obviously, don't
want one user's default mailbox to reference another user's mailbox.

I'm not thrilled by the circular references there.


-- 
Bill Moseley
moseley at hank.org




More information about the thelist mailing list