SQL: set existing column as Primary Key in MySQL

MysqlSqlIndexingPrimary Key

Mysql Problem Overview


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.

Mysql Solutions


Solution 1 - Mysql

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)

Solution 2 - Mysql

ALTER TABLE your_table
ADD PRIMARY KEY (Drugid);

Solution 3 - Mysql

If you want to do it with phpmyadmin interface:

Select the table -> Go to structure tab -> On the row corresponding to the column you want, click on the icon with a key

Solution 4 - Mysql

alter table table_name
add constraint myprimarykey primary key(column);

reference : http://www.w3schools.com/sql/sql_primarykey.asp

Solution 5 - Mysql

Go to localhost/phpmyadmin and press enter key. Now select:

database --> table_name --->Structure --->Action  ---> Primary -->click on Primary 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkrasatosView Question on Stackoverflow
Solution 1 - MysqlypercubeᵀᴹView Answer on Stackoverflow
Solution 2 - Mysqljuergen dView Answer on Stackoverflow
Solution 3 - MysqlOrtigaView Answer on Stackoverflow
Solution 4 - MysqlRavi KameshView Answer on Stackoverflow
Solution 5 - MysqlS K TANDONView Answer on Stackoverflow