On Tue, Nov 13, 2001 at 11:03:00PM -0600, Christian Stromberger wrote:
>
> I understand that an index is used to "speed stuff up", but am foggy
> on the details.

You might find this helpful:

http://www.linux-mag.com/2001-06/mysql_01.html

> Eg, let's say I have an "authors" table with fname, mname, and lname
> fields for first, middle and last names.  Plus an auto_increment
> primary key.  I will want to sort on author last name for output of
> sorted authors, and also want to prevent duplicate author names from
> being inserted.  So, how would I set up an appropriate index, and
> then how would I use it in the client code?
>
>
> I assume I set up the index like so in the create table:
> ...
> unique index (lname, fname, mname) ?

That would help prevent duplication, yes.

> Do I give the index a name?

If you don't, MySQL will invent one for you.

> I notice this is optional in the syntax.  What's the reason to
> give/not give an index a name?

So that if you get an error that involves an index and MySQL tells you
the index name, you might recognise it. :-)

> How do I tell my client code to "use the index" for sorting?
>
> select lname, fname
> from authors
> order by ...?
> 
> Any advice for this newbie appreciated.

MySQL selects the index to use for a query automatically.

Jeremy
-- 
Jeremy D. Zawodny, <[EMAIL PROTECTED]>
Technical Yahoo - Yahoo Finance
Desk: (408) 349-7878   Fax: (408) 349-5454   Cell: (408) 685-5936

MySQL 3.23.41-max: up 70 days, processed 1,539,436,651 queries (254/sec. avg)

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