SQL Unique Key Syntax

孤人 提交于 2020-01-02 05:39:05

问题


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;

回答1:


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.



来源:https://stackoverflow.com/questions/17197473/sql-unique-key-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!