* [EMAIL PROTECTED]
> 1 reason and 1 reason only.  To speed up queries.

I would say there are three reasons to use indexes:

1) To speed up queries
2) To create constraints
3) To maintain a sort order

If you have an order table and an order_line table, it is important that
line no 1 only exists once for each order.

order table:
order_no
customer_id
order_date

order_line table:
order_no
line_no
product_id
qty

For the order_line table, an unique index[1] on (order_no,line_no) will make
sure there is only one line no 1 for each order. It will also speed up
queries involving order_line, and also make sure the sort order of the lines
are correct, normally without the need of explicitly specifying ORDER BY.

[1] This could be the primary key, or just a 'normal' unique index.

--
Roger
sql


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