SQL: set existing column as Primary Key in MySQL

krasatos picture krasatos · Mar 14, 2012 · Viewed 136.1k times · Source

I have a database with 3 columns:

id, name, somethingelse  

This table has no index set and i am getting "No index defined!" in phpmyadmin
id is a 7digit alphanumeric value, unique to each row.
I want to set Drugid to be the primarykey/index (i dont know the difference if there is one)
Please explain in detail as i am new to this.
Thank you.

Answer

ypercubeᵀᴹ picture ypercubeᵀᴹ · Mar 14, 2012

Either run in SQL:

ALTER TABLE tableName
  ADD PRIMARY KEY (id)           ---or Drugid, whichever you want it to be PK

or use the PHPMyAdmin interface (Table Structure)