September 2nd, 2002, 02:43 PM
How to check if index exists ?
is there any way to find out if an index already exists in a table for a specific field?
I made an install script that automatically creates some tables and places some indexes. Just wanted to make sure that an index isn't set twice just in cace a user runs the script twice.
Thougt of something like:
IF NOT EXISTS INDEX(whatever).....
This is my original PHP-query to create the index:
Any ideas on how to change that line would be very helpfull!
@$setindex = mysql_query("ALTER TABLE ".$tablename." ADD INDEX (browserstamp)");
September 2nd, 2002, 03:29 PM
Use either DESCRIBE table or SHOW INDEX FROM table and parse the output from that. Then you'll know if there's an index or not.
But if you fear that they run the script twice, why not go for checking if the table exists first?
Like CREATE TABLE IF NOT EXISTS...
UN*X is sexy!
who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep