KEY `cat_parent_id` (`cat_parent_id`),

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mannyee
Forum Newbie
Posts: 10
Joined: Tue Dec 08, 2009 4:41 am

KEY `cat_parent_id` (`cat_parent_id`),

Post by mannyee »

hi guys!!

while going through a tutorial, i found the following query used in it:
CREATE TABLE IF NOT EXISTS `tbl_category` (
`cat_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`cat_parent_id` int(11) NOT NULL DEFAULT '0',
`cat_name` varchar(50) NOT NULL DEFAULT '',
`cat_description` varchar(200) NOT NULL DEFAULT '',
`cat_image` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`cat_id`),
KEY `cat_parent_id` (`cat_parent_id`),
KEY `cat_name` (`cat_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

and here i am confused about the use of
KEY `cat_parent_id` (`cat_parent_id`),
KEY `cat_name` (`cat_name`)
why are they used?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: KEY `cat_parent_id` (`cat_parent_id`),

Post by John Cartwright »

KEY's are used to index the particular column to allow the quick retrieval of that particular data. However, they take up more memory so it's important to only use keys on columns that are used store the relationships (foreign keys) between tables, and highly searched columns.

See http://www.google.ca/search?q=database+ ... =firefox-a for more info.
Post Reply