SQL keys, MUL vs PRI vs UNI

Deadly 提交于 2019-11-29 06:43:32

摘自:http://stackoverflow.com/questions/5317889/sql-keys-mul-vs-pri-vs-uni/15268888#15268888


SQL keys, MUL vs PRI vs UNI

DESCRIBE <table>;

This is acutally a shortcut for:

SHOW COLUMNS FROM <table>;

In any case, there are three possible values for the "Key" attribute:

  • PRI

  • UNI

  • MUL

The meaning of PRI and UNI are quite clear:

PRI => primary key

UNI=> unique key

The third possibility, MUL, (which you asked about) is basically an index that is neither a primary key nor a unique key. The name comes from "multiple" because multiple occurences of the same value are allowed. Straight from the MySQL documentation:http://dev.mysql.com/doc/refman/5.1/en/show-columns.html


"If Key is MUL, the column is the first column of a nonunique index in which multiple occurrences of a given value are permitted within the column."


There is also a final caveat:


"If more than one of the Key values applies to a given column of a table, Key displays the one with the highest priority, in the order PRI, UNI, MUL."


As a general note, the MySQL documentation is quite good. When in doubt, check it out!

====END====

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!