db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Ventura <st.ne...@gmail.com>
Subject Re: how to make two attributes unique?
Date Mon, 10 Oct 2011 09:40:34 GMT
What you need is an UNIQUE constraint with more than one column.
Follow the reference on ALTER TABLE syntax here:

In your case, the statement is:

ALTER TABLE my_table ADD CONSTRAINT unique_ou_per_div UNIQUE ( divisionId, ou )

Update: Just realized that the above documentation does not clearly
indicate that there can be multiple columns inside the parenthesis.
Maybe we should file a doc bug?

On Mon, Oct 10, 2011 at 5:19 AM, Spezifikum <info@spezifikum.com> wrote:
> Hi,
> i have organisational units (ou) within divisions. The name within the
> division should be unique.
> ou:
> name=CHAR(80)
> divisionID=INT CONSTRAINT OperationalUnitDivisionID_FK REFERENCES division
> These two attributes should be unique in combination.
> I only found many examples on how to make one attribute unique, but i guess
> this is a dumb newbie question - sorry.
> As a side note: There never will be OUs nested within OUs.
> Thanks
> Malte

View raw message