Frage

Very basic question; I'm very new to SQL and trying to decipher an example data base.

In the below create table code, why does the define primary key syntax reference only the 'id' column once in parentheses but the unique key definition references the 'category' column twice? both before and within the parentheses.

Seems like there is a simple answer to this but cant track one down:

CREATE TABLE `categories` (
  `id` SMALLINT NOT NULL AUTO_INCREMENT,
  `category` VARCHAR(30) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `category` (`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
War es hilfreich?

Lösung

It is the key name, and it's not mandatory. See the doc about it : http://dev.mysql.com/doc/refman/5.1/en/create-table.html.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top