- SELECT k.column_name
- FROM information_schema.table_constraints t
- JOIN information_schema.key_column_usage k
- USING (constraint_name,table_schema,table_name)
- WHERE t.constraint_type='PRIMARY KEY'
- AND t.table_schema='TABLE'
- AND t.table_name='TABLE_NAME'
例子
- SELECT k.column_name
- FROM information_schema.table_constraints t
- JOIN information_schema.key_column_usage k
- USING (constraint_name,table_schema,table_name)
- WHERE t.constraint_type='PRIMARY KEY'
- AND t.table_schema='test'
- AND t.table_name='tests'
结果
转载请注明:谷谷点程序 » mysql找出表中的主键