Select the primary key for a table

/ Published in: SQL
Save to your folder(s)

Copy this code and paste it in your HTML
  1. SELECT k.column_name
  2. FROM information_schema.table_constraints t
  3. JOIN information_schema.key_column_usage k
  4. USING(constraint_name,table_schema,TABLE_NAME)
  5. WHERE t.constraint_type='PRIMARY KEY'
  6. AND t.table_schema='db'
  7. AND t.table_name='tbl';


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.