View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 10:32 AM
Rik Wasmus
 
Posts: n/a
Default Re: Non unique primary key

On Tue, 05 Feb 2008 02:30:12 +0100, Kurda Yon <kurdayon@yahoo.com> wrote:
> Is that allowed to have identical values in a column which is declared
> as "primary key".


No.

> Is that true that rows of the table will be ordered
> by values of elements of the primary-key-column (in the sense that the
> MySQL server does not need order rows each time when the select
> command is used)?


No.

ALTER TABLE tablename ORDER BY fieldname
<http://dev.mysql.com/doc/refman/5.0/en/alter-table.html>
However:
"Note that the table does not remain in this order after inserts and
deletes.

Also take a look at:
<http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html>

> What should I do if I want to have my rows be ordered with respect a
> column which may have identical values?


Just order by that column, and as long as you don't specify a second
column, or even all values are equal, the order of equals is
unpredictable, but should logically not matter.
--
Rik Wasmus
Reply With Quote