MySQL - 如何获取 table 的主键?

MySQL - How to get primary key of a table?

谁能告诉我如何在 MySQL 中获取 table 的主键?

试试这个:

解决方案一:

这是来自Ajons Answer

SELECT k.COLUMN_NAME
FROM information_schema.table_constraints t
LEFT JOIN information_schema.key_column_usage k
USING(constraint_name,table_schema,table_name)
WHERE t.constraint_type='PRIMARY KEY'
    AND t.table_schema=DATABASE()
    AND t.table_name='owalog';

方案二:

这是来自alexn

SHOW KEYS FROM tablename WHERE Key_name = 'PRIMARY'

方案三:

SHOW INDEX FROM presort.final_conf_score_mld_run2 
WHERE Key_name = 'PRIMARY';