SQL:在MySQL中将现有列设置为主键 [英] SQL: set existing column as Primary Key in MySQL

查看:775
本文介绍了SQL:在MySQL中将现有列设置为主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含3列的数据库:

I have a database with 3 columns:

id, name, somethingelse  

此表没有设置索引,我得到没有定义索引!在phpmyadmin中

id是一个7位数的字母数字值,每行都是唯一的。

我想将Drugid设置为主键/索引(我不知道存在差异的区别)

请详细解释我是新手。

谢谢。

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.

推荐答案

在SQL中运行:

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

或使用PHPMyAdmin界面(表结构)

or use the PHPMyAdmin interface (Table Structure)

这篇关于SQL:在MySQL中将现有列设置为主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆