How to get primary key of table?

前端 未结 14 2322
不思量自难忘°
不思量自难忘° 2020-12-02 15:01

Is there a way to get the name of primary key field from mysql-database? For example:

I have a table like this:

+----+------+
| id | name |
+----+---         


        
14条回答
  •  没有蜡笔的小新
    2020-12-02 15:30

    A better way is to use SHOW KEYS since you don't always have access to information_schema. The following works:

    SHOW KEYS FROM table WHERE Key_name = 'PRIMARY'
    

    Column_name will contain the name of the primary key.

提交回复
热议问题