Re: Creating a table with two keys?

From: James B. Reynolds <jbreynol_at_ix.netcom.com>
Date: 1996/10/27
Message-ID: <5500ns$nq2_at_sjx-ixn6.ix.netcom.com>#1/1


Brian,

You can create a primary key consisting of one or more columns. A primary key value must be unique and not null. You can also create additional indexes on as many of the columns in the table as you desire so you could index one (or more) of the columns that compose part of your composite primary key. It all depends on how you want to access the data. Based on your example it appears that you want to create a composite primary key consiting of two columns. In order to do this you must use a table constraint as opposed to a column constraint: create table class
  (
    semester_code char(3),

    course_num      smallint,
    hours           float       not null
   constraint pk_code_course primary key (semester_code, course_num))

Hope this helps.

Jim Reynolds  

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
> )
>
>Thanks for any help,
>
>Brian Master
Received on Sun Oct 27 1996 - 00:00:00 CEST

Original text of this message