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;
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top