MySQL 查询 唯一约束 对应的字段,列名称合并 SELECT F.DbName,F.TableName,F.ConstraintName,GROUP_CONCAT(ColumnName) ColumnName FROM ( SELECT t1.TABLE_SCHEMA DbName, t1.TABLE_NAME TableName,t1.CONSTRAINT_NAME ConstraintName,t2.COLUMN_NAME ColumnName FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS t1 LEFT JOIN information_schema.KEY_COLUMN_USAGE t2 ON t1.CONSTRAINT_NAME=t2.CONSTRAINT_NAME and t1.TABLE_SCHEMA = t2.TABLE_SCHEMA WHERE T1.CONSTRAINT_TYPE in ('UNIQUE','PRIMARY') -- 唯一约束 和 主键 and T1.TABLE_NAME = 'sys_user' -- 表名称 and T1.TABLE_SCHEMA='xxx_ocr' -- 库名称 ) F WHERE F.ConstraintName = 'UserId' -- 去掉这个 约束名称 就是所有唯一约束和主键 group by F.DbName,F.TableName,F.ConstraintName 附录: