Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP MySQL Check If A Table Has A Primary Key

What would I query my MySQL server to check if a table has a primary key or not? Something like:


if(mysql_send("SELECT TABLE table HAS PRIMARY KEY") == TRUE) {
   // do stuff here
}

like image 752
NoodleOfDeath Avatar asked Feb 13 '11 05:02

NoodleOfDeath


1 Answers

SHOW INDEXES FROM TABLE WHERE Key_name = 'PRIMARY'
like image 85
Gustavo Costa De Oliveira Avatar answered Nov 15 '22 02:11

Gustavo Costa De Oliveira