简体   繁体   English

SQL唯一键语法

[英]SQL Unique Key Syntax

Very basic question; 非常基本的问题; I'm very new to SQL and trying to decipher an example data base. 我是SQL的新手并试图破译示例数据库。

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? 在下面的创建表代码中,为什么define主键语法仅在括号中引用'id'列,但唯一键定义引用'category'列两次? 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 . 请参阅相关文档: http//dev.mysql.com/doc/refman/5.1/en/create-table.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM