Skip to content

Instantly share code, notes, and snippets.

@jachin
Created June 21, 2011 04:33
Show Gist options
  • Save jachin/1037246 to your computer and use it in GitHub Desktop.
Save jachin/1037246 to your computer and use it in GitHub Desktop.
Select the primary key for a table
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='db'
AND t.table_name='tbl';
@jachin
Copy link
Author

jachin commented Jun 21, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment