How do I show unique constraints of a table in MySQL?

This query returns primay keys, unique keys and foreign ones :

show indexes from table_name;

select distinct CONSTRAINT_NAME
from information_schema.TABLE_CONSTRAINTS
where table_name = 'table_name' and constraint_type = 'UNIQUE';

select distinct CONSTRAINT_NAME
from information_schema.TABLE_CONSTRAINTS
where CONSTRAINT_SCHEMA = 'mysql'

This doesn't produce elegant output but is easy to remember:

SHOW CREATE TABLE table_name;

Tags:

Mysql

Database