The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
two primary key in one table
Discuss two primary key in one table in the MySQL Help forum on Dev Shed. two primary key in one table MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 4th, 2000, 02:21 PM
|
|
Junior Member
|
|
Join Date: May 2000
Posts: 13
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
here I have a question,
can one table consists of 2 primary key ? thank you.
|

May 5th, 2000, 01:16 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
You can't have two primary keys in a single table.
Only one primary key is allowded in a single table.
------------------
SR -
shiju.dreamcenter.net
|

May 5th, 2000, 02:54 AM
|
|
Junior Member
|
|
Join Date: May 2000
Posts: 13
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
i know one table can have 2 index keys but can't have 2 primary key. But in mysql how to add index key.
for example:
State lookup table:
(3 fields:country_id,state_id,statedesc)
data:
record 1('sg','st1','Happy State')
record 1('sg','st2','Perfect State')
record 1('sg','st3','Hello State')
record 1('tw','st1','Apple State')
record 1('tw','st2','Orange State')
record 1('tw','st3','Star State')
record 1('tw','st4','Bird State')
I want to set country_id and state_id as index key. how to do ? thank you.
|

May 5th, 2000, 06:36 AM
|
|
Junior Member
|
|
Join Date: May 2000
Location: Heerlen, The Netherlands
Posts: 24
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|

May 5th, 2000, 08:33 AM
|
|
Contributing User
|
|
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Make a composite primary key when you create the table.
> create table state_lookup(
> country_id varchar(10) not null,
> state_id varchar(10) not null,
> statedesc varchar(50),
> primary key(country_id, state_id));
|

May 8th, 2000, 01:51 PM
|
|
Junior Member
|
|
Join Date: May 2000
Posts: 13
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thanks for your helps
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|