I found a way to have two primary key, if those keys relate on many
columns.

mysql> create table keytest(
    -> col1 int not null,
    -> col2 int not null,
    -> unique index (id1,id2),
    -> unique index (id2,id1)
Query OK, 0 rows affected (0.01 sec)

mysql> describe keytest;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id1   | int(11) |      | PRI | 0       |       |
| id2   | int(11) |      | PRI | 0       |       |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)

here ya go, two primary key.
in my app, it's very useful for the tables linking two other tables (two
tables are N:N so the middle one links)

+---------+     +-----------+     +----------+
| users   |     | userdepts |     | depts    |
+---------+     +-----------+     +----------+
| usrID   |----<| usrID     |>----| deptID   |
| usrDept |     | deptID    |     | deptName |
| usrName |     +-----------+     +----------+
+---------+

(do you like my relational DB ascii figure?

Then when selecting all linked entried, it uses only the index! Since
it's only numbers and the indexes for search in each directions are
there..

HTH
Etienne

sherzodR wrote:
> 
> As far as I know, you can't do tht. What you could do instead is
> have one Primary Key col and make another one UNIQUE.
> 
> I did that several times, and it does work!
> 
> --
> 
> What they need to teach in school is for people to think for themselves.  :-)
>              -- Larry Wall in <[EMAIL PROTECTED]>
> 
> Demirchyan Oganes-AOD098 wrote:
> 
>     DO: Hello everyone,
>     DO:
>     DO: I have this create table statement,
>     DO:
>     DO: drop table IF EXISTS GROUP_CONCLUSION_GROUPING CASCADE;
>     DO:
>     DO: CREATE TABLE IF NOT EXISTS GROUP_CONCLUSION_GROUPING(
>     DO: ANALYSIS_RESULT_ID     MEDIUMINT(20)  PRIMARY KEY REFERENCES   
>PAD_ANALYSIS_RESULT(ANALYSIS_RESULT_ID),
>     DO: GROUP_CONCLUSION_ID    MEDIUMINT(20)  PRIMARY KEY REFERENCES   
>GROUP_CONCLUSION(GROUP_CONCLUSION_ID)
>     DO:                                                                              
>                                                   ) Type=InnoDB;
>     DO:
>     DO: where I want to create table with 2 primary keys, but it won't let me.
>     DO:
>     DO: How could I do it.
>     DO:
>     DO: Regards,
>     DO:
>     DO: Oganes Demirchyan
>     DO: Motorola Life Science
>     DO: 757 S.Raymond
>     DO: Pasadena, CA  91105
>     DO: Tel: 626-584-5900
>     DO: email: [EMAIL PROTECTED]
>     DO:
>     DO:
>     DO: ---------------------------------------------------------------------
>     DO: Before posting, please check:
>     DO:    http://www.mysql.com/manual.php   (the manual)
>     DO:    http://lists.mysql.com/           (the list archive)
>     DO:
>     DO: To request this thread, e-mail <[EMAIL PROTECTED]>
>     DO: To unsubscribe, e-mail 
><[EMAIL PROTECTED]>
>     DO: Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>     DO:
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

-- 
Etienne Marcotte
Specifications Management - Quality Control
Imperial Tobacco Ltd. - Montreal (Qc) Canada
514.932.6161 x.4001

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to