Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primary key versus key

When creating a mysql dump containing the structure of my database, one of the tables shows the following:

CREATE TABLE `completedTransactions` (
  `paymentId` int(10) unsigned NOT NULL,
  `timestamp` int(15) unsigned NOT NULL,
  `actionTaken` varchar(25) NOT NULL,
  `response` varchar(255) NOT NULL,
  `responseCode` int(5) NOT NULL,

  PRIMARY KEY  (`paymentId`,`timestamp`),
  KEY `paymentId` (`paymentId`),

The primary key is what I was expecting, but I'm unsure what the last line is about?

KEY `paymentId` (`paymentId`),

Is this related to an index?

like image 870
user167850 Avatar asked Feb 04 '10 11:02

user167850


2 Answers

Yes, the KEY keyword is just an alias for the INDEX keyword.

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
  ...
  {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
      [index_option] ...

Source: MySQL Documentation: CREATE TABLE

like image 181
Daniel Vassallo Avatar answered Oct 13 '22 18:10

Daniel Vassallo


KEY is not unique, PRIMARY KEY and UNIQUE KEY are uniques.

like image 36
Notinlist Avatar answered Oct 13 '22 20:10

Notinlist