Primary key versus key

后端 未结 3 1296
盖世英雄少女心
盖世英雄少女心 2021-02-07 19:19

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

CREATE TABLE `completedTransactions` (
  `paymentId` i         


        
相关标签:
3条回答
  • 2021-02-07 19:57

    KEY is not unique, PRIMARY KEY and UNIQUE KEY are uniques.

    0 讨论(0)
  • 2021-02-07 20:15

    Quoting the documentation of CREATE TABLE :

    KEY is normally a synonym for INDEX.
    The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.

    0 讨论(0)
  • 2021-02-07 20:21

    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] ...
    

    Source: MySQL Documentation: CREATE TABLE

    0 讨论(0)
提交回复
热议问题