聘我网

新概念招聘3.0

怎么给表添加一个主键?

vote up0vote downstar

以下是两次失败的尝试:

mysql> alter table shared_videos add column `id` int(10) unsigned AUTO_INCREMENT;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
mysql> alter table shared_videos add column `id` int(10) unsigned primary AUTO_INCREMENT;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AUTO_INCREMENT' at line 1
 

1 个答复

vote up0vote downcheck

两种方式:

alter table shared_videos add column `id` int(10) unsigned primary KEY AUTO_INCREMENT;

或者

ALTER TABLE shared_videos ADD COLUMN id int(10) AUTO_INCREMENT NOT NULL, 

ADD PRIMARY KEY(id);
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.