Federico Schwindt wrote:

> hi,
>
>   i'm not sure if this belongs here, but i cannot seem to find the
> answer anywhere else.
>   first, what's the difference between:
>
>   PRIMARY KEY (key1, key2)
>   PRIMARY KEY (key1), KEY (key2)

The first line creates a single, unique key on the columns key1 and key2.

The second line creates two keys, the first a unique key on key1 and the
second on just key2 that allows duplicates.



>   second, let's suppose the following table:
>
>   owner_id int(11),
>   customer_id int(11),
>   customer_info varchar(100)
>
>   and i want to search either by owner_id and customer_id.
>   can i do this w/o creating the indexes by hand? or do i have to
> create'em explicity and specify which one i'm gonna use before
> performing a query?

You never need keys to query a table.  It just makes the query much faster.
 For a query like "WHERE owner_id=X AND custoerm_id=Y" you would want a
composite index on both columns, e.g. KEY( owner_id, customer_id ).  This
key would also cover a query that had just "WHERE owner_id=X".  If, then,
you wanted to query on just the customer_id, you would want to add another
key on just customer_id.

E.g.:
CREATE TABLE tbl (
  owner_id int(11),
  customer_id int(11),
  customer_info varchar(100)
  key( owner_id, customer_id ),
  key( customer_id )
);

Of course, study the documentation for further explanation info.

b.



---------------------------------------------------------------------
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