Re: Creating a table with two keys?

From: Jack L. Swayze Sr. <keystrk_at_feist.com>
Date: 1996/10/27
Message-ID: <55099k$26m_at_wormer.fn.net>#1/1


In <3272A6FE.482D_at_tam2000.tamu.edu> Brian Master <bem6681_at_tam2000.tamu.edu> writes:
>
>I know this is probably a simple question, but how do I create a table
>with two primary keys? Here is what I tried, but it doesn't work:
>
> create table class
> (
> semester_code char(3) not null primary key,
> course_num smallint not null primary key,
> hours float not null
> )
>

Of course, if you want to create a Boyce-Codd normal form table, (a table with two independently unique conditions) you will need to 1) pick one of the columns to be the primary key or 2) abandon the use of primary key for this table. I recommend #1. for example:

create tabe class (
  semester_code char(3) not null primary key,  course_num smallint not null,
 hours float not null );

create unique index class_alternate_key on class (course_num); <--- may need to verify this syntax.

However, by the look of what you are wanting to do, you really want to create a composite key (like the previous response showed you).


'Keystroke'
KeystrkTX_at_AOL.COM Received on Sun Oct 27 1996 - 00:00:00 CEST

Original text of this message