SQL keys, MUL vs PRI vs UNI

后端 未结 5 581
独厮守ぢ
独厮守ぢ 2020-11-28 00:57

What is the difference between MUL, PRI and UNI in MySQL?

I\'m working on a MySQL query, using the command:

de         


        
5条回答
  •  猫巷女王i
    2020-11-28 01:13

    UNI: For UNIQUE:

    • It is a set of one or more columns of a table to uniquely identify the record.
    • A table can have multiple UNIQUE key.
    • It is quite like primary key to allow unique values but can accept one null value which primary key does not.

    PRI: For PRIMARY:

    • It is also a set of one or more columns of a table to uniquely identify the record.
    • A table can have only one PRIMARY key.
    • It is quite like UNIQUE key to allow unique values but does not allow any null value.

    MUL: For MULTIPLE:

    • It is also a set of one or more columns of a table which does not identify the record uniquely.
    • A table can have more than one MULTIPLE key.
    • It can be created in table on index or foreign key adding, it does not allow null value.
    • It allows duplicate entries in column.
    • If we do not specify MUL column type then it is quite like a normal column but can allow null entries too hence; to restrict such entries we need to specify it.
    • If we add indexes on column or add foreign key then automatically MUL key type added.

提交回复
热议问题