How to get primary key of table?

前端 未结 14 2331
不思量自难忘°
不思量自难忘° 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:46

    SELECT k.column_name
    FROM information_schema.key_column_usage k   
    WHERE k.table_name = 'YOUR TABLE NAME' AND k.constraint_name LIKE 'pk%'
    

    I would recommend you to watch all the fields

提交回复
热议问题