How can I find which column is the primary key of a table by using a query?
This is a duplicate question:
credit to Lukmdo for this answer:
It might be not advised but works just fine:
show index from TABLE where Key_name = 'PRIMARY' ;
The solid way is to use information_schema:
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';