coffeemonitor
coffeemonitor

Reputation: 13120

Mysql Index Keyname Importance

I run this query:

SHOW INDEX FROM `tbl_clients`

I get back these:

Table, Non_unique, Key_name, Seq_in_index, Column_name, Collation, Cardinality, Sub_part, Null, Index_type, Comment

I am pretty sure the Key_name is for human recognizing purposes only. But before I start creating my indexes, I wanted to be sure I was correct.

If I'm correct, I intend to name my primary keys PRIMARY, rather than the same name of the Column_name.

So, I really just need someone to validate me, or tell me otherwise.

Upvotes: 3

Views: 4248

Answers (2)

Adrian Cornish
Adrian Cornish

Reputation: 23848

It will be called primary. You can have only one primary key hence the name. Otherwise you are right - its just a human readable name

CREATE TABLE `foobar` (
  `pk` int(11) NOT NULL,
  `c` char(10) DEFAULT NULL,
  PRIMARY KEY (`pk`),
  KEY `k_foowoo` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

mysql> show index from foobar;
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table  | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| foobar |          0 | PRIMARY  |            1 | pk          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| foobar |          1 | k_foowoo |            1 | c           | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               |
+--------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

Upvotes: 0

zerkms
zerkms

Reputation: 254886

The name is for humans only, so don't worry

Upvotes: 12

Related Questions