If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Two primary keys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-03-04, 16:27
ok_computer ok_computer is offline
Registered User
 
Join Date: Oct 2004
Posts: 7
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
Reply With Quote
  #2 (permalink)  
Old 12-03-04, 20:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
what does "it works like there are set as two different keys and not like one" mean?

can you show the CREATE TABLE statement?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-04-04, 03:21
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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?
Reply With Quote
  #4 (permalink)  
Old 12-04-04, 11:17
ok_computer ok_computer is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 12-04-04, 11:22
ok_computer ok_computer is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 12-04-04, 12:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by ok_computer
the problem got solved. I don't know how.
me neither
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On