For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > August 2004 > primary keys and an index









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author primary keys and an index
davidklonski

2004-08-18, 3:57 pm

Hello MySQL gurus

Assuming I create the following table:

CREATE TABLE table (
ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
Column1 INT UNSIGNED NOT NULL,
Column2 VARCHAR(255) NOT NULL,
PRIMARY KEY (ID)
) ENGINE=MYISAM DEFAULT CHARSET=latin1;

Now ID is the primary key of the table which means it has a unique
index on it (right?)

will adding the following have any additional effect?
CREATE index_name ON table(ID);

Or is such an index automatically created for all the primary keys in
a table?

Also, putting storage issues aside, what would be the divantages to
creating an index for every column that I use in a join, (in order to
speed things up)?

thanks for the help



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


Barand

2004-08-18, 3:57 pm

Primary key (ID) is already a unique index.

As for divantages, can't see any besides storage.

Also, if you regularly have queries which ... ORDER BY column2,
column1 ... then it may be worth considering an index on those
fields.

Barand

http://members.aol.com/barryaandrew...agridguide.html easy
data tables - and more

----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com