Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: constraint question

Re: constraint question

From: <kennethkoenraadt_at_no-spam.hotmail.com>
Date: Sun, 08 Sep 2002 20:01:44 GMT
Message-ID: <3d7ba7e2.2160416@news.mobilixnet.dk>

On Sun, 08 Sep 2002 23:48:21 +0000, eugene kim <eugene1977_at_hotmail.com> wrote:

>hi..
>i'm a beginner sql programmer..
>
>if there's a better place to ask fundemantal sql questions like this..
>pls inform me,,
>
>my question is,
>
>create table teams(
> team_id integer primary key,
> school_id integer references schools,
> sport varchar(100),
> gender char
>);
>
>if ( school_id, sport, gender) uniquely identifies a team entity just like
>team_id can uniquely do so.
>
>is it better to have a constraint such as
>(school_id, sport, gender) unique
>in my table?
>
>well that will prevent users to insert duplicate data into table..
>
>so i guess it's better to have the constraint
>instead of forcing application programmer to check the condition..?
>
>thank you

Hi Eugene,

It depends...if your TEAMS table is referenced by other tables, it is clearly better to have a simple Integer PK (Team_id) referenced than a long composite key. Performs better and requires less space. In that case you may even create a PK constraint on Team_id AND a unique constraint on (school_id, sport, gender).

If your TEAMS table is not referenced by other tables, it may not be worth the effort to implement an integer PK. Then you could just use (school_id, sport, gender) as a PK. But consider the possibility of (school_id, sport, gender) some day not being unique any more (a school may suddenly have 2 male basket teams...and your application dies just as suddenly). Simple integer PK's taken from a sequence are always unique...

Received on Sun Sep 08 2002 - 15:01:44 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US