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 |
+----+---
SELECT kcu.column_name, kcu.ordinal_position
FROM information_schema.table_constraints tc
INNER JOIN information_schema.key_column_usage kcu
ON tc.CONSTRAINT_CATALOG = kcu.CONSTRAINT_CATALOG
AND tc.CONSTRAINT_SCHEMA = kcu.CONSTRAINT_SCHEMA
AND tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME
WHERE tc.table_schema = schema() -- only look in the current schema
AND tc.constraint_type = 'PRIMARY KEY'
AND tc.table_name = '' -- specify your table.
ORDER BY kcu.ordinal_position