Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CREATE TABLE statement explanation

Status
Not open for further replies.

misc1

Programmer
Apr 17, 2005
1
SI
Hello,
I found an article which is describing how to develop site engine with PHP supported with MYSQL database.
Since I'm new to php and mysql I have a question on CREATE TABLE statemet that was used in that article.
What I don't quite understand is what is the purpose of UNIQUE KEY `bl_ID` (`bl_ID`) and KEY `bl_ID_2` (`bl_ID`) lines in statements below:

# Table: 'block_location'
#
CREATE TABLE `block_location` (
`bl_ID` int(11) NOT NULL auto_increment,
`block_ID` int(11) default '0',
`block_row` int(11) default '0',
`block_col` int(11) default '0',
`block_page` varchar(255) default 'all',
`site_ID` int(11) default '1',
`user_ID` int(11) default '0',
PRIMARY KEY (`bl_ID`),
UNIQUE KEY `bl_ID` (`bl_ID`),
KEY `bl_ID_2` (`bl_ID`)
) TYPE=MyISAM;


# Table: 'blocks'
#
CREATE TABLE `blocks` (
`block_ID` int(11) NOT NULL auto_increment,
`block_title` varchar(255) default 'Block Title',
`block_file` varchar(255) default '0',
`plugin_ID` int(11) default '0',
`group_ID` int(11) default '0',
`site_ID` int(11) default NULL,
`mod_ID` int(11) default NULL,
PRIMARY KEY (`block_ID`),
UNIQUE KEY `block_ID` (`block_ID`),
KEY `block_ID_2` (`block_ID`)
) TYPE=MyISAM;

Thanks
Misc
 
You have three indexes on each primary-key field, two of which are superfluous. You should get rid of them both by (in the case of the 'blocks' table):[tt]
ALTER TABLE blocks
DROP KEY block_id,
DROP KEY block_id_2[/tt]
and the same for the 'block_location' table.

Having unnecessary indexes is harmless, but it makes updates slower.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top