SQL唯一键语法 [英] SQL Unique Key Syntax

查看:213
本文介绍了SQL唯一键语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常基本的问题;我对SQL非常陌生,试图解密一个示例数据库。

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

在下面的create table代码中,为什么定义主键语法只引用'id '列在括号中,但唯一键定义引用类别列两次?

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;


推荐答案

这是键的名称,查看相关文档: http://dev.mysql.com /doc/refman/5.1/en/create-table.html

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.

这篇关于SQL唯一键语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆