views:

54

answers:

1

Following is the code to create a table in mysql database.

CREATE TABLE IF NOT EXISTS `hightraffic` (
  `id` int(11) NOT NULL auto_increment,
  `videoID` int(11) NOT NULL default '0',
  `userid` int(11) NOT NULL,
  `name` varchar(255) NOT NULL default '',
  `title` int(11) NOT NULL default '0',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`),
  KEY `videoID ` (`videoID `),
  KEY `date` (`date`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=342 ;

I want to know following:

  1. What is KEY, is it primary key or its a index ?
  2. Why there are KEY applied on videoID and date?
  3. If there will be no KEY on videoId and date then is there any performance issues, Or if its there then what are the performance benefits and why?
+2  A: 
  1. KEY is just an index.
  2. It's YOUR schema, an odd question to ask. Did you just find this online somewhere? You may want to read up on database indexes.
  3. If there are no keys (indexes) on those values, you won't be able to benefit from an index when filtering by those columns. See the above link.
Artem Russakovskii