Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004

    Unanswered: primary key constraints

    hi all i have a table like this

    id int8 NOT NULL,
    appid int8,
    userid int8,
    CONSTRAINT pkey PRIMARY KEY (id, appid , userid),

    what i want is the id field has to be unique, but i want a 1 to many relationship for the userid and appid

    eg appid can exist for many userids but userid can only have 1 appid

    can someone help me with the primary key, my pkey does't work, it still allows userid to have multiple appids

    many thanks
    Last edited by plork123; 10-28-05 at 04:37.

  2. #2
    Join Date
    Feb 2005
    Colorado Springs
    First off, I see promotionid in your primary key definition but not listed as a field in the table. Second, appid and user id do not have NOT NULL set. You are always going to run into trouble if you allow NULL values in a key. If id is unique, then perhaps using id alone for the primary key would be good. Finally, if you want a constraint that userid can have only one appid, then perhaps the easiest way to do this is with a BEFORE INSERT OR UPDATE trigger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts