Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2004
    Posts
    7

    Unanswered: Two primary keys

    I am newbie in My Sql. Can somebody tell me how can I set two primary keys in a table? I set PRIMARY KEY (id1,id2) but it works like there are set as two different keys and not like one. I tried to add id1=1 id2=2 and id1=1 id2=3 but My Sql reurned an error

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what does "it works like there are set as two different keys and not like one" mean?

    can you show the CREATE TABLE statement?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    when you say 2 primary keys
    do you mean 1 primary and 1 unique key (ie 2 separate columns) - although this would suggest your data model is invalid and carrying redundant information.
    OR 1 Primary key that is a composite of 2 columns?

  4. #4
    Join Date
    Oct 2004
    Posts
    7
    Quote Originally Posted by r937
    what does "it works like there are set as two different keys and not like one" mean?

    can you show the CREATE TABLE statement?
    The problem solved by itself. Thank you very much. the table was
    CREATE TABLE `price` (
    `barcode` smallint(15) NOT NULL default '0',
    `shop_id` smallint(6) NOT NULL default '0',
    `price` double(15,2) default NULL,
    PRIMARY KEY (`barcode`,`shop_id`)
    ) TYPE=MyISAM

  5. #5
    Join Date
    Oct 2004
    Posts
    7
    Quote Originally Posted by healdem
    when you say 2 primary keys
    do you mean 1 primary and 1 unique key (ie 2 separate columns) - although this would suggest your data model is invalid and carrying redundant information.
    OR 1 Primary key that is a composite of 2 columns?
    My friend thank you very much for the reply. the problem got solved. I don't know how. When I say two primary keys I mean two columns that form One primary key. It is used for many to many relationships. Thank you again

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by ok_computer
    the problem got solved. I don't know how.
    me neither
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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