SQL: set existing column as Primary Key in MySQL

前端 未结 5 915
北恋
北恋 2021-01-31 13:23

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

相关标签:
5条回答
  • 2021-01-31 13:55
    alter table table_name
    add constraint myprimarykey primary key(column);
    

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

    0 讨论(0)
  • 2021-01-31 13:57

    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

    0 讨论(0)
  • 2021-01-31 14:02

    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)

    0 讨论(0)
  • 2021-01-31 14:05
    ALTER TABLE your_table
    ADD PRIMARY KEY (Drugid);
    
    0 讨论(0)
  • 2021-01-31 14:10

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

    database --> table_name --->Structure --->Action  ---> Primary -->click on Primary 
    
    0 讨论(0)
提交回复
热议问题