主键与键 [英] Primary key versus key

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

问题描述

创建包含数据库结构的mysql转储时,其中一张表显示以下内容:

When creating a mysql dump containing the structure of my database, one of the tables shows the following:

CREATE TABLE `completedTransactions` (
  `paymentId` int(10) unsigned NOT NULL,
  `timestamp` int(15) unsigned NOT NULL,
  `actionTaken` varchar(25) NOT NULL,
  `response` varchar(255) NOT NULL,
  `responseCode` int(5) NOT NULL,

  PRIMARY KEY  (`paymentId`,`timestamp`),
  KEY `paymentId` (`paymentId`),

主键是我期望的,但是我不确定最后一行是什么?

The primary key is what I was expecting, but I'm unsure what the last line is about?

KEY `paymentId` (`paymentId`),

这与索引有关吗?

推荐答案

是的,KEY关键字只是INDEX关键字的别名.

Yes, the KEY keyword is just an alias for the INDEX keyword.

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
  ...
  {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
      [index_option] ...

来源: MySQL文档:创建表

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

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